Skip to content

Commit 04cf798

Browse files
committed
Work
1 parent 397fd1c commit 04cf798

File tree

10 files changed

+976
-638
lines changed

10 files changed

+976
-638
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ set(${PROJECT_NAME}_INSTALL_INCLUDEDIR
9090
set(CMAKE_AUTOMOC ON)
9191
set(CMAKE_AUTORCC ON)
9292

93-
find_package(${Qt} ${QtMinVersion} REQUIRED Core Network Gui Test Sql)
93+
find_package(${Qt} ${QtMinVersion} REQUIRED Core Network Gui Test Sql CorePrivate)
9494
get_filename_component(Qt_Prefix "${${Qt}_DIR}/../../../.." ABSOLUTE)
9595

9696
find_package(${Qt}Keychain REQUIRED)

Quotient/connection.cpp

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#include <QtCore/QRegularExpression>
4848
#include <QtCore/QStandardPaths>
4949
#include <QtCore/QStringBuilder>
50+
#include <QtSql/QSqlDatabase>
51+
#include <QtSql/QSqlQuery>
5052
#include <QtNetwork/QDnsLookup>
5153
#include <qt6keychain/keychain.h>
5254

@@ -369,14 +371,48 @@ void Connection::Private::setupCryptoMachine(const QByteArray& picklingKey)
369371
mxIdForDb.replace(u':', u'_');
370372
const QString databasePath{QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
371373
% 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+
372392
cryptoMachine = crypto::init(stringToRust(q->userId()), stringToRust(q->deviceId()),
373-
stringToRust(databasePath), bytesToRust(picklingKey));
393+
stringToRust(databasePath), bytesToRust(picklingKey.toBase64()), stringToRust(accountPickle));
374394
if (!(*cryptoMachine)->is_ok()) {
375395
qCritical() << "Failed to load crypto machine"
376396
<< static_cast<int>((*cryptoMachine)->error())
377397
<< stringFromRust((*cryptoMachine)->error_string());
378398
qApp->exit(1);
379399
}
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+
}
380416
}
381417

382418
void Connection::Private::completeSetup(const QString& mxId, bool newLogin,
@@ -730,17 +766,6 @@ void Connection::Private::processOutgoingRequests()
730766
}));
731767
break;
732768
}
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-
}
744769
}
745770
}
746771

0 commit comments

Comments
 (0)