diff options
author | Tobias Fella <fella@posteo.de> | 2022-05-19 14:11:18 +0200 |
---|---|---|
committer | Tobias Fella <fella@posteo.de> | 2022-05-19 14:11:18 +0200 |
commit | 41897df408c1398881bb8cf82ae0dc4503cefef7 (patch) | |
tree | 5169881124427db161b8ec15601406d825b35977 /lib | |
parent | b29eb3954b798ac9110906cd79c4f288deaa2596 (diff) | |
download | libquotient-41897df408c1398881bb8cf82ae0dc4503cefef7.tar.gz libquotient-41897df408c1398881bb8cf82ae0dc4503cefef7.zip |
Use list of 3-tuple instead of map
Diffstat (limited to 'lib')
-rw-r--r-- | lib/database.cpp | 22 | ||||
-rw-r--r-- | lib/database.h | 2 | ||||
-rw-r--r-- | lib/room.cpp | 4 |
3 files changed, 13 insertions, 15 deletions
diff --git a/lib/database.cpp b/lib/database.cpp index 3255e5e7..0119b35c 100644 --- a/lib/database.cpp +++ b/lib/database.cpp @@ -346,20 +346,18 @@ QOlmOutboundGroupSessionPtr Database::loadCurrentOutboundMegolmSession(const QSt return nullptr; } -void Database::setDevicesReceivedKey(const QString& roomId, const QHash<QString, QList<std::pair<QString, QString>>>& devices, const QString& sessionId, int index) +void Database::setDevicesReceivedKey(const QString& roomId, const QVector<std::tuple<QString, QString, QString>>& devices, const QString& sessionId, int index) { transaction(); - for (const auto& user : devices.keys()) { - for (const auto& [device, curveKey] : devices[user]) { - auto query = prepareQuery(QStringLiteral("INSERT INTO sent_megolm_sessions(roomId, userId, deviceId, identityKey, sessionId, i) VALUES(:roomId, :userId, :deviceId, :identityKey, :sessionId, :i);")); - query.bindValue(":roomId", roomId); - query.bindValue(":userId", user); - query.bindValue(":deviceId", device); - query.bindValue(":identityKey", curveKey); - query.bindValue(":sessionId", sessionId); - query.bindValue(":i", index); - execute(query); - } + for (const auto& [user, device, curveKey] : devices) { + auto query = prepareQuery(QStringLiteral("INSERT INTO sent_megolm_sessions(roomId, userId, deviceId, identityKey, sessionId, i) VALUES(:roomId, :userId, :deviceId, :identityKey, :sessionId, :i);")); + query.bindValue(":roomId", roomId); + query.bindValue(":userId", user); + query.bindValue(":deviceId", device); + query.bindValue(":identityKey", curveKey); + query.bindValue(":sessionId", sessionId); + query.bindValue(":i", index); + execute(query); } commit(); } diff --git a/lib/database.h b/lib/database.h index 8bef332f..ef251d66 100644 --- a/lib/database.h +++ b/lib/database.h @@ -46,7 +46,7 @@ public: // Returns a map UserId -> [DeviceId] that have not received key yet QHash<QString, QStringList> devicesWithoutKey(const QString& roomId, QHash<QString, QStringList>& devices, const QString &sessionId); - void setDevicesReceivedKey(const QString& roomId, const QHash<QString, QList<std::pair<QString, QString>>>& devices, const QString& sessionId, int index); + void setDevicesReceivedKey(const QString& roomId, const QVector<std::tuple<QString, QString, QString>>& devices, const QString& sessionId, int index); private: void migrateTo1(); diff --git a/lib/room.cpp b/lib/room.cpp index 5d3ae329..3696f808 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -537,10 +537,10 @@ public: } if (!usersToDevicesToEvents.empty()) { connection->sendToDevices("m.room.encrypted", usersToDevicesToEvents); - QHash<QString, QList<std::pair<QString, QString>>> receivedDevices; + QVector<std::tuple<QString, QString, QString>> receivedDevices; for (const auto& user : devices.keys()) { for (const auto& device : devices[user]) { - receivedDevices[user] += {device, q->connection()->curveKeyForUserDevice(user, device) }; + receivedDevices += {user, device, q->connection()->curveKeyForUserDevice(user, device) }; } } connection->database()->setDevicesReceivedKey(q->id(), receivedDevices, sessionId, index); |