fix: Fix crash when calling getUnacknowledgedRatchets for a new Jid

This commit is contained in:
PapaTutuWawa 2022-08-18 16:21:53 +02:00
parent f68e45af26
commit 80e1b20f27
2 changed files with 8 additions and 7 deletions

View File

@ -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<List<int>> getUnacknowledgedRatchets(String jid) async {
Future<List<int>?> getUnacknowledgedRatchets(String jid) async {
return _lock.synchronized(() async {
final ret = List<int>.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;
});
}
/// Mark the ratchet for device [deviceId] from [jid] as acked.

View File

@ -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,
);
});