From 7a41f4726f7881644cfb195aef4654ad07415938 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Wed, 20 May 2020 10:36:05 +0200 Subject: [PATCH] properly persist inbound group session indexes --- lib/src/database/database.g.dart | 15 +++++++++++++++ lib/src/database/database.moor | 1 + lib/src/room.dart | 6 +++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/src/database/database.g.dart b/lib/src/database/database.g.dart index c5c20a2..61bc1c7 100644 --- a/lib/src/database/database.g.dart +++ b/lib/src/database/database.g.dart @@ -4978,6 +4978,21 @@ abstract class _$Database extends GeneratedDatabase { ); } + Future updateInboundGroupSessionIndexes( + String indexes, int client_id, String room_id, String session_id) { + return customUpdate( + 'UPDATE inbound_group_sessions SET indexes = :indexes WHERE client_id = :client_id AND room_id = :room_id AND session_id = :session_id', + variables: [ + Variable.withString(indexes), + Variable.withInt(client_id), + Variable.withString(room_id), + Variable.withString(session_id) + ], + updates: {inboundGroupSessions}, + updateKind: UpdateKind.update, + ); + } + Future storeUserDeviceKeysInfo( int client_id, String user_id, bool outdated) { return customInsert( diff --git a/lib/src/database/database.moor b/lib/src/database/database.moor index 97cf8e9..ebe66ea 100644 --- a/lib/src/database/database.moor +++ b/lib/src/database/database.moor @@ -164,6 +164,7 @@ dbGetInboundGroupSessionKey: SELECT * FROM inbound_group_sessions WHERE client_i dbGetInboundGroupSessionKeys: SELECT * FROM inbound_group_sessions WHERE client_id = :client_id AND room_id = :room_id; getAllInboundGroupSessions: SELECT * FROM inbound_group_sessions WHERE client_id = :client_id; storeInboundGroupSession: INSERT OR REPLACE INTO inbound_group_sessions (client_id, room_id, session_id, pickle, content, indexes) VALUES (:client_id, :room_id, :session_id, :pickle, :content, :indexes); +updateInboundGroupSessionIndexes: UPDATE inbound_group_sessions SET indexes = :indexes WHERE client_id = :client_id AND room_id = :room_id AND session_id = :session_id; storeUserDeviceKeysInfo: INSERT OR REPLACE INTO user_device_keys (client_id, user_id, outdated) VALUES (:client_id, :user_id, :outdated); setVerifiedUserDeviceKey: UPDATE user_device_keys_key SET verified = :verified WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id; setBlockedUserDeviceKey: UPDATE user_device_keys_key SET blocked = :blocked WHERE client_id = :client_id AND user_id = :user_id AND device_id = :device_id; diff --git a/lib/src/room.dart b/lib/src/room.dart index 18a9b7d..c6fbb98 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1872,7 +1872,11 @@ class Room { } inboundGroupSessions[sessionId].indexes[messageIndexKey] = decryptResult.message_index; - _storeOutboundGroupSession(); + // now we persist the udpated indexes into the database. + // the entry should always exist. In the case it doesn't, the following + // line *could* throw an error. As that is a future, though, and we call + // it un-awaited here, nothing happens, which is exactly the result we want + client.database?.updateInboundGroupSessionIndexes(json.encode(inboundGroupSessions[sessionId].indexes), client.id, id, sessionId); decryptedPayload = json.decode(decryptResult.plaintext); } catch (exception) { // alright, if this was actually by our own outbound group session, we might as well clear it