Merge branch 'soru/persist-inbound-session-index' into 'master'

properly persist inbound group session indexes

See merge request famedly/famedlysdk!316
This commit is contained in:
Christian Pauly 2020-05-21 06:25:57 +00:00
commit 9fad348d22
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