Skip to content

Commit

Permalink
Try fixing some setup things
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasFella committed Nov 4, 2024
1 parent 1fda4d1 commit 2bf6831
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions Quotient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,31 +392,44 @@ void Connection::Private::completeSetup(const QString& mxId, bool newLogin,
const std::optional<QString>& deviceId,
const std::optional<QString>& accessToken)
{
data->setIdentity(mxId, deviceId.value_or(u""_s), accessToken.value_or(u""_s).toLatin1());
q->setObjectName(data->userId() % u'/' % data->deviceId());
qCDebug(MAIN) << "Using server" << data->baseUrl().toDisplayString()
<< "by user" << data->userId()
<< "from device" << data->deviceId();
connect(qApp, &QCoreApplication::aboutToQuit, q, &Connection::saveState);
setupPicklingKey();

if (accessToken.has_value()) {
q->loadVersions();
q->loadCapabilities();
q->user()->load(); // Load the local user's profile
}
auto doCompleteSetup = [this, mxId, deviceId, accessToken](){
data->setIdentity(mxId, deviceId.value_or(u""_s), accessToken.value_or(u""_s).toLatin1());
q->setObjectName(data->userId() % u'/' % data->deviceId());
qCDebug(MAIN) << "Using server" << data->baseUrl().toDisplayString()
<< "by user" << data->userId()
<< "from device" << data->deviceId();
connect(qApp, &QCoreApplication::aboutToQuit, q, &Connection::saveState);
setupPicklingKey();

if (accessToken.has_value()) {
q->loadVersions();
q->loadCapabilities();
q->user()->load(); // Load the local user's profile
}

emit q->stateChanged(); // Technically connected to the homeserver but no E2EE yet
emit q->stateChanged(); // Technically connected to the homeserver but no E2EE yet

if (useEncryption) {
emit q->encryptionChanged(useEncryption);
emit q->stateChanged();
emit q->ready();
emit q->connected();
if (useEncryption) {
emit q->encryptionChanged(useEncryption);
emit q->stateChanged();
emit q->ready();
emit q->connected();
} else {
qCInfo(E2EE) << "End-to-end encryption (E2EE) support is off for" << q->objectName();
emit q->ready();
emit q->connected();
}
};
if (newLogin) {
auto mxIdForDb = q->userId();
mxIdForDb.replace(u':', u'_');
const QString databasePath{ QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) % u'/' % mxIdForDb % u'/' % q->deviceId() };
QDir(databasePath).removeRecursively();
runKeychainJob(new QKeychain::DeletePasswordJob(qAppName()), q->userId() % u"-Pickle"_s).then([doCompleteSetup](const auto &) {
doCompleteSetup();
});
} else {
qCInfo(E2EE) << "End-to-end encryption (E2EE) support is off for" << q->objectName();
emit q->ready();
emit q->connected();
doCompleteSetup();
}
}

Expand Down

0 comments on commit 2bf6831

Please sign in to comment.