properly persist inbound group session indexes

This commit is contained in:
Sorunome 2020-05-20 10:36:05 +02:00
parent 11d788b68f
commit 7a41f4726f
No known key found for this signature in database
GPG key ID: B19471D07FC9BE9C
3 changed files with 21 additions and 1 deletions

View file

@ -4978,6 +4978,21 @@ abstract class _$Database extends GeneratedDatabase {
);
}
Future<int> 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<int> storeUserDeviceKeysInfo(
int client_id, String user_id, bool outdated) {
return customInsert(

View file

@ -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;

View file

@ -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