From 8991599a0b8d98c8ede8b9648f70f6624cfc3218 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sun, 11 Sep 2022 17:26:54 +0200 Subject: [PATCH] feat: Allow removing all ratchets for a given Jid --- lib/src/omemo/sessionmanager.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/src/omemo/sessionmanager.dart b/lib/src/omemo/sessionmanager.dart index 278fb75..5d7bbc7 100644 --- a/lib/src/omemo/sessionmanager.dart +++ b/lib/src/omemo/sessionmanager.dart @@ -441,6 +441,24 @@ class OmemoSessionManager { }); } + /// Removes all ratchets for Jid [jid]. Triggers a DeviceMapModified event at the end and an + /// RatchetRemovedEvent for each ratchet. + Future removeAllRatchets(String jid) async { + await _lock.synchronized(() async { + for (final deviceId in _deviceMap[jid]!) { + // Remove the ratchet + _ratchetMap.remove(RatchetMapKey(jid, deviceId)); + // Commit it + _eventStreamController.add(RatchetRemovedEvent(jid, deviceId)); + } + + // Remove the device from jid + _deviceMap.remove(jid); + // Commit it + _eventStreamController.add(DeviceMapModifiedEvent(_deviceMap)); + }); + } + /// 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 {