|
47 | 47 | #include <QtCore/QRegularExpression>
|
48 | 48 | #include <QtCore/QStandardPaths>
|
49 | 49 | #include <QtCore/QStringBuilder>
|
| 50 | +#include <QtSql/QSqlDatabase> |
| 51 | +#include <QtSql/QSqlQuery> |
50 | 52 | #include <QtNetwork/QDnsLookup>
|
51 | 53 | #include <qt6keychain/keychain.h>
|
52 | 54 |
|
@@ -369,14 +371,48 @@ void Connection::Private::setupCryptoMachine(const QByteArray& picklingKey)
|
369 | 371 | mxIdForDb.replace(u':', u'_');
|
370 | 372 | const QString databasePath{QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
|
371 | 373 | % u'/' % mxIdForDb % u'/' % q->deviceId()};
|
| 374 | + |
| 375 | + QString accountPickle; |
| 376 | + bool hasDb = QFileInfo(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + u'/' + mxIdForDb + "/quotient_%1.db3"_L1.arg(q->deviceId())).exists(); |
| 377 | + if (hasDb) { |
| 378 | + auto db = QSqlDatabase::addDatabase(u"QSQLITE"_s, "Quotient_"_L1 + q->deviceId()); |
| 379 | + const QString databasePath{ QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) % u'/' % mxIdForDb }; |
| 380 | + QDir(databasePath).mkpath("."_L1); |
| 381 | + db.setDatabaseName(databasePath + "/quotient_%1.db3"_L1.arg(q->deviceId())); |
| 382 | + db.open(); |
| 383 | + QSqlQuery query(db); |
| 384 | + query.prepare(u"SELECT pickle FROM accounts;"_s); |
| 385 | + query.exec(); |
| 386 | + query.next(); |
| 387 | + accountPickle = query.value(0).toString(); |
| 388 | + |
| 389 | + db.close(); |
| 390 | + } |
| 391 | + |
372 | 392 | cryptoMachine = crypto::init(stringToRust(q->userId()), stringToRust(q->deviceId()),
|
373 |
| - stringToRust(databasePath), bytesToRust(picklingKey)); |
| 393 | + stringToRust(databasePath), bytesToRust(picklingKey.toBase64()), stringToRust(accountPickle)); |
374 | 394 | if (!(*cryptoMachine)->is_ok()) {
|
375 | 395 | qCritical() << "Failed to load crypto machine"
|
376 | 396 | << static_cast<int>((*cryptoMachine)->error())
|
377 | 397 | << stringFromRust((*cryptoMachine)->error_string());
|
378 | 398 | qApp->exit(1);
|
379 | 399 | }
|
| 400 | + |
| 401 | + if (hasDb) { |
| 402 | + auto db = QSqlDatabase::addDatabase(u"QSQLITE"_s, "Quotient_"_L1 + q->deviceId()); |
| 403 | + const QString databasePath{ QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) % u'/' % mxIdForDb }; |
| 404 | + QDir(databasePath).mkpath("."_L1); |
| 405 | + db.setDatabaseName(databasePath + "/quotient_%1.db3"_L1.arg(q->deviceId())); |
| 406 | + db.open(); |
| 407 | + |
| 408 | + QSqlQuery query(db); |
| 409 | + query.prepare(u"SELECT * FROM inbound_megolm_sessions;"_s); |
| 410 | + query.exec(); |
| 411 | + while(query.next()) { |
| 412 | + (*cryptoMachine)->inbound_from_libolm_pickle(stringToRust(query.value("pickle").toString()), bytesToRust(picklingKey.toBase64()), stringToRust(query.value("roomId").toString()), stringToRust(query.value("senderKey").toString()), stringToRust(query.value("senderClaimedEd25519Key").toString())); |
| 413 | + } |
| 414 | + // QFile(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + u'/' + mxIdForDb + "/quotient_%1.db3"_L1.arg(q->deviceId())).remove(); |
| 415 | + } |
380 | 416 | }
|
381 | 417 |
|
382 | 418 | void Connection::Private::completeSetup(const QString& mxId, bool newLogin,
|
@@ -730,17 +766,6 @@ void Connection::Private::processOutgoingRequests()
|
730 | 766 | }));
|
731 | 767 | break;
|
732 | 768 | }
|
733 |
| - case 6: { // keys backup |
734 |
| - futures.append(QFuture<void>( |
735 |
| - q->callApi<PutRoomKeysJob>(stringFromRust(request.keys_backup_version()), |
736 |
| - fromRustJson<QHash<RoomId, RoomKeyBackup>>( |
737 |
| - request.keys_backup_rooms())) |
738 |
| - .onResult([this, id](const auto& job) { |
739 |
| - (*cryptoMachine) |
740 |
| - ->mark_keys_backup_as_sent(bytesToRust(job->rawData()), stringToRust(id)); |
741 |
| - }))); |
742 |
| - break; |
743 |
| - } |
744 | 769 | }
|
745 | 770 | }
|
746 | 771 |
|
|
0 commit comments