aboutsummaryrefslogtreecommitdiff
path: root/lib/database.cpp
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-05-25 22:48:53 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-05-29 08:21:27 +0200
commit64797165f04a16d290dd27c2f962060b40f85be3 (patch)
treed7a862543711fa5fc7876134612549fce59144cd /lib/database.cpp
parentc2e9256b1c334bdadcc208429084cbc83496fb4b (diff)
downloadlibquotient-64797165f04a16d290dd27c2f962060b40f85be3.tar.gz
libquotient-64797165f04a16d290dd27c2f962060b40f85be3.zip
Refactor creation of Megolm sessions in Room
Notably, replace a multi-level hash map with QMultiHash and factor out Room::P::createOlmSession().
Diffstat (limited to 'lib/database.cpp')
-rw-r--r--lib/database.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/database.cpp b/lib/database.cpp
index 0119b35c..193ff54e 100644
--- a/lib/database.cpp
+++ b/lib/database.cpp
@@ -307,20 +307,22 @@ void Database::setOlmSessionLastReceived(const QString& sessionId, const QDateTi
commit();
}
-void Database::saveCurrentOutboundMegolmSession(const QString& roomId, const PicklingMode& picklingMode, const QOlmOutboundGroupSessionPtr& session)
+void Database::saveCurrentOutboundMegolmSession(
+ const QString& roomId, const PicklingMode& picklingMode,
+ const QOlmOutboundGroupSession& session)
{
- const auto pickle = session->pickle(picklingMode);
+ const auto pickle = session.pickle(picklingMode);
if (pickle) {
auto deleteQuery = prepareQuery(QStringLiteral("DELETE FROM outbound_megolm_sessions WHERE roomId=:roomId AND sessionId=:sessionId;"));
deleteQuery.bindValue(":roomId", roomId);
- deleteQuery.bindValue(":sessionId", session->sessionId());
+ deleteQuery.bindValue(":sessionId", session.sessionId());
auto insertQuery = prepareQuery(QStringLiteral("INSERT INTO outbound_megolm_sessions(roomId, sessionId, pickle, creationTime, messageCount) VALUES(:roomId, :sessionId, :pickle, :creationTime, :messageCount);"));
insertQuery.bindValue(":roomId", roomId);
- insertQuery.bindValue(":sessionId", session->sessionId());
+ insertQuery.bindValue(":sessionId", session.sessionId());
insertQuery.bindValue(":pickle", pickle.value());
- insertQuery.bindValue(":creationTime", session->creationTime());
- insertQuery.bindValue(":messageCount", session->messageCount());
+ insertQuery.bindValue(":creationTime", session.creationTime());
+ insertQuery.bindValue(":messageCount", session.messageCount());
transaction();
execute(deleteQuery);
@@ -362,7 +364,9 @@ void Database::setDevicesReceivedKey(const QString& roomId, const QVector<std::t
commit();
}
-QHash<QString, QStringList> Database::devicesWithoutKey(const QString& roomId, QHash<QString, QStringList>& devices, const QString &sessionId)
+QMultiHash<QString, QString> Database::devicesWithoutKey(
+ const QString& roomId, QMultiHash<QString, QString> devices,
+ const QString& sessionId)
{
auto query = prepareQuery(QStringLiteral("SELECT userId, deviceId FROM sent_megolm_sessions WHERE roomId=:roomId AND sessionId=:sessionId"));
query.bindValue(":roomId", roomId);
@@ -371,7 +375,8 @@ QHash<QString, QStringList> Database::devicesWithoutKey(const QString& roomId, Q
execute(query);
commit();
while (query.next()) {
- devices[query.value("userId").toString()].removeAll(query.value("deviceId").toString());
+ devices.remove(query.value("userId").toString(),
+ query.value("deviceId").toString());
}
return devices;
}