Skip to content

Commit 2bf6831

Browse files
committed
Try fixing some setup things
1 parent 1fda4d1 commit 2bf6831

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

Quotient/connection.cpp

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -392,31 +392,44 @@ void Connection::Private::completeSetup(const QString& mxId, bool newLogin,
392392
const std::optional<QString>& deviceId,
393393
const std::optional<QString>& accessToken)
394394
{
395-
data->setIdentity(mxId, deviceId.value_or(u""_s), accessToken.value_or(u""_s).toLatin1());
396-
q->setObjectName(data->userId() % u'/' % data->deviceId());
397-
qCDebug(MAIN) << "Using server" << data->baseUrl().toDisplayString()
398-
<< "by user" << data->userId()
399-
<< "from device" << data->deviceId();
400-
connect(qApp, &QCoreApplication::aboutToQuit, q, &Connection::saveState);
401-
setupPicklingKey();
402-
403-
if (accessToken.has_value()) {
404-
q->loadVersions();
405-
q->loadCapabilities();
406-
q->user()->load(); // Load the local user's profile
407-
}
395+
auto doCompleteSetup = [this, mxId, deviceId, accessToken](){
396+
data->setIdentity(mxId, deviceId.value_or(u""_s), accessToken.value_or(u""_s).toLatin1());
397+
q->setObjectName(data->userId() % u'/' % data->deviceId());
398+
qCDebug(MAIN) << "Using server" << data->baseUrl().toDisplayString()
399+
<< "by user" << data->userId()
400+
<< "from device" << data->deviceId();
401+
connect(qApp, &QCoreApplication::aboutToQuit, q, &Connection::saveState);
402+
setupPicklingKey();
403+
404+
if (accessToken.has_value()) {
405+
q->loadVersions();
406+
q->loadCapabilities();
407+
q->user()->load(); // Load the local user's profile
408+
}
408409

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

411-
if (useEncryption) {
412-
emit q->encryptionChanged(useEncryption);
413-
emit q->stateChanged();
414-
emit q->ready();
415-
emit q->connected();
412+
if (useEncryption) {
413+
emit q->encryptionChanged(useEncryption);
414+
emit q->stateChanged();
415+
emit q->ready();
416+
emit q->connected();
417+
} else {
418+
qCInfo(E2EE) << "End-to-end encryption (E2EE) support is off for" << q->objectName();
419+
emit q->ready();
420+
emit q->connected();
421+
}
422+
};
423+
if (newLogin) {
424+
auto mxIdForDb = q->userId();
425+
mxIdForDb.replace(u':', u'_');
426+
const QString databasePath{ QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) % u'/' % mxIdForDb % u'/' % q->deviceId() };
427+
QDir(databasePath).removeRecursively();
428+
runKeychainJob(new QKeychain::DeletePasswordJob(qAppName()), q->userId() % u"-Pickle"_s).then([doCompleteSetup](const auto &) {
429+
doCompleteSetup();
430+
});
416431
} else {
417-
qCInfo(E2EE) << "End-to-end encryption (E2EE) support is off for" << q->objectName();
418-
emit q->ready();
419-
emit q->connected();
432+
doCompleteSetup();
420433
}
421434
}
422435

0 commit comments

Comments
 (0)