From 662f18d86e6e5d6037cb8cb1f4a952618263fc00 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 18 Feb 2020 13:37:36 +0000 Subject: [PATCH] [Client] Free everything --- lib/src/client.dart | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 08a4d01..c7d8914 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -33,6 +33,7 @@ import 'package:famedlysdk/src/sync/user_update.dart'; import 'package:famedlysdk/src/utils/device_keys_list.dart'; import 'package:famedlysdk/src/utils/matrix_file.dart'; import 'package:famedlysdk/src/utils/open_id_credentials.dart'; +import 'package:famedlysdk/src/utils/session_key.dart'; import 'package:famedlysdk/src/utils/to_device_event.dart'; import 'package:famedlysdk/src/utils/turn_server_credentials.dart'; import 'package:olm/olm.dart' as olm; @@ -740,6 +741,16 @@ class Client { /// Resets all settings and stops the synchronisation. void clear() { + olmSessions.values.forEach((List sessions) { + sessions.forEach((olm.Session session) => session?.free()); + }); + rooms.forEach((Room room) { + room.clearOutboundGroupSession(); + room.sessionKeys.values.forEach((SessionKey sessionKey) { + sessionKey.inboundGroupSession?.free(); + }); + }); + this._olmAccount?.free(); this.storeAPI?.clear(); this._accessToken = this._homeserver = this._userID = this._deviceID = this ._deviceName = @@ -1603,9 +1614,11 @@ class Client { if (!_olmSessions.containsKey(curve25519IdentityKey)) { _olmSessions[curve25519IdentityKey] = []; } - _olmSessions[curve25519IdentityKey] - .removeWhere((olm.Session s) => s.session_id() == session.session_id()); - _olmSessions[curve25519IdentityKey].add(session); + if (_olmSessions[curve25519IdentityKey] + .indexWhere((s) => s.session_id() == session.session_id()) == + -1) { + _olmSessions[curve25519IdentityKey].add(session); + } Map> pickleMap = {}; for (var entry in olmSessions.entries) { pickleMap[entry.key] = [];