From a4589b6e09ee0d7c0b6c96930b6478b2ceb0987c Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Thu, 11 Aug 2022 12:02:21 +0200 Subject: [PATCH] feat: Allow access to the device map --- lib/src/omemo/sessionmanager.dart | 15 ++++++++++++--- test/serialisation_test.dart | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/src/omemo/sessionmanager.dart b/lib/src/omemo/sessionmanager.dart index 4e9a13a..7dc8721 100644 --- a/lib/src/omemo/sessionmanager.dart +++ b/lib/src/omemo/sessionmanager.dart @@ -386,13 +386,22 @@ class OmemoSessionManager { _eventStreamController.add(DeviceModifiedEvent(_device)); }); } + + /// Returns the device map, i.e. the mapping of bare Jid to its device identifiers + /// we have built sessions with. + Future>> getDeviceMap() async { + Map>? map; + + await _lock.synchronized(() async { + map = _deviceMap; + }); + + return map!; + } @visibleForTesting OmemoDoubleRatchet getRatchet(String jid, int deviceId) => _ratchetMap[RatchetMapKey(jid, deviceId)]!; - @visibleForTesting - Map> getDeviceMap() => _deviceMap; - @visibleForTesting Map getRatchetMap() => _ratchetMap; diff --git a/test/serialisation_test.dart b/test/serialisation_test.dart index ae6fdaa..4951543 100644 --- a/test/serialisation_test.dart +++ b/test/serialisation_test.dart @@ -93,7 +93,7 @@ void main() { final oldDevice = await oldSession.getDevice(); final newDevice = await newSession.getDevice(); expect(await oldDevice.equals(newDevice), true); - expect(oldSession.getDeviceMap(), newSession.getDeviceMap()); + expect(await oldSession.getDeviceMap(), await newSession.getDeviceMap()); expect(oldSession.getRatchetMap().length, newSession.getRatchetMap().length); for (final session in oldSession.getRatchetMap().entries) {