From 797bf6985638f0fe5a6e12a7a8339cf7d9334f88 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Fri, 9 Dec 2022 18:42:23 +0100 Subject: [PATCH] fix: Crash when calling getDevicesTrust for unknown Jid --- lib/src/trust/btbv.dart | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/src/trust/btbv.dart b/lib/src/trust/btbv.dart index abb125d..9bfc7a2 100644 --- a/lib/src/trust/btbv.dart +++ b/lib/src/trust/btbv.dart @@ -122,17 +122,20 @@ abstract class BlindTrustBeforeVerificationTrustManager extends TrustManager { }); } - /// Returns a mapping from the device identifiers of [jid] to their trust state. + /// Returns a mapping from the device identifiers of [jid] to their trust state. If + /// there are no devices known for [jid], then an empty map is returned. Future> getDevicesTrust(String jid) async { - final map = {}; + return _lock.synchronized(() async { + final map = {}; - await _lock.synchronized(() async { + if (!devices.containsKey(jid)) return map; + for (final deviceId in devices[jid]!) { map[deviceId] = trustCache[RatchetMapKey(jid, deviceId)]!; } - }); - return map; + return map; + }); } /// Sets the trust of [jid]'s device with identifier [deviceId] to [state].