From fe1ba99b14b516ecf6d147c57bd986d8afe7f3fc Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Fri, 9 Dec 2022 20:41:53 +0100 Subject: [PATCH] feat: Indicate whether a ratchet has been created or not --- lib/src/omemo/events.dart | 9 ++++----- lib/src/omemo/sessionmanager.dart | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/src/omemo/events.dart b/lib/src/omemo/events.dart index 89359c1..71b7f9b 100644 --- a/lib/src/omemo/events.dart +++ b/lib/src/omemo/events.dart @@ -5,16 +5,17 @@ abstract class OmemoEvent {} /// Triggered when a ratchet has been modified class RatchetModifiedEvent extends OmemoEvent { - - RatchetModifiedEvent(this.jid, this.deviceId, this.ratchet); + RatchetModifiedEvent(this.jid, this.deviceId, this.ratchet, this.added); final String jid; final int deviceId; final OmemoDoubleRatchet ratchet; + + /// Indicates whether the ratchet has just been created (true) or just modified (false). + final bool added; } /// Triggered when a ratchet has been removed and should be removed from storage. class RatchetRemovedEvent extends OmemoEvent { - RatchetRemovedEvent(this.jid, this.deviceId); final String jid; final int deviceId; @@ -22,7 +23,6 @@ class RatchetRemovedEvent extends OmemoEvent { /// Triggered when the device map has been modified class DeviceMapModifiedEvent extends OmemoEvent { - DeviceMapModifiedEvent(this.map); final Map> map; } @@ -30,7 +30,6 @@ class DeviceMapModifiedEvent extends OmemoEvent { /// Triggered by the OmemoSessionManager when our own device bundle was modified /// and thus should be republished. class DeviceModifiedEvent extends OmemoEvent { - DeviceModifiedEvent(this.device); final Device device; } diff --git a/lib/src/omemo/sessionmanager.dart b/lib/src/omemo/sessionmanager.dart index 5ddaf29..77a06f5 100644 --- a/lib/src/omemo/sessionmanager.dart +++ b/lib/src/omemo/sessionmanager.dart @@ -28,7 +28,6 @@ import 'package:synchronized/synchronized.dart'; const omemoPayloadInfoString = 'OMEMO Payload'; class OmemoSessionManager { - OmemoSessionManager(this._device, this._deviceMap, this._ratchetMap, this._trustManager) : _lock = Lock(), _deviceLock = Lock(), @@ -136,7 +135,7 @@ class OmemoSessionManager { _ratchetMap[key] = ratchet; // Commit the ratchet - _eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet)); + _eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet, true)); }); } @@ -321,7 +320,7 @@ class OmemoSessionManager { } // Commit the ratchet - _eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet)); + _eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet, false)); } } }); @@ -346,6 +345,7 @@ class OmemoSessionManager { mapKey.jid, mapKey.deviceId, oldRatchet, + false, ), ); }); @@ -421,6 +421,7 @@ class OmemoSessionManager { senderJid, senderDeviceId, oldRatchet, + false, ), ); @@ -476,7 +477,14 @@ class OmemoSessionManager { } // Commit the ratchet - _eventStreamController.add(RatchetModifiedEvent(senderJid, senderDeviceId, ratchet)); + _eventStreamController.add( + RatchetModifiedEvent( + senderJid, + senderDeviceId, + ratchet, + false, + ), + ); try { return _decryptAndVerifyHmac(ciphertext, keyAndHmac); @@ -606,7 +614,7 @@ class OmemoSessionManager { ..acknowledged = true; // Commit it - _eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet)); + _eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet, false)); }); }