From 80e1b20f2721d6ed04e80b8abfec4df52b462a11 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Thu, 18 Aug 2022 16:21:53 +0200 Subject: [PATCH] fix: Fix crash when calling getUnacknowledgedRatchets for a new Jid --- lib/src/omemo/sessionmanager.dart | 13 +++++++------ test/omemo_test.dart | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/src/omemo/sessionmanager.dart b/lib/src/omemo/sessionmanager.dart index 6e670cc..542e21a 100644 --- a/lib/src/omemo/sessionmanager.dart +++ b/lib/src/omemo/sessionmanager.dart @@ -446,18 +446,19 @@ class OmemoSessionManager { /// Returns the list of device identifiers belonging to [jid] that are yet unacked, i.e. /// we have not yet received an empty OMEMO message from. - Future> getUnacknowledgedRatchets(String jid) async { - final ret = List.empty(growable: true); + Future?> getUnacknowledgedRatchets(String jid) async { + return _lock.synchronized(() async { + final ret = List.empty(growable: true); + final devices = _deviceMap[jid]; + if (devices == null) return null; - await _lock.synchronized(() async { - final devices = _deviceMap[jid]!; for (final device in devices) { final ratchet = _ratchetMap[RatchetMapKey(jid, device)]!; if (!ratchet.acknowledged) ret.add(device); } - }); - return ret; + return ret; + }); } /// Mark the ratchet for device [deviceId] from [jid] as acked. diff --git a/test/omemo_test.dart b/test/omemo_test.dart index dcd8c3f..c755b4b 100644 --- a/test/omemo_test.dart +++ b/test/omemo_test.dart @@ -539,7 +539,7 @@ void main() { // Alice marks the ratchet as acknowledged await aliceSession.ratchetAcknowledged(bobJid, await bobSession.getDeviceId()); expect( - (await aliceSession.getUnacknowledgedRatchets(bobJid)).isEmpty, + (await aliceSession.getUnacknowledgedRatchets(bobJid))!.isEmpty, true, ); });