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) {