feat: Indicate whether a ratchet has been created or not
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
PapaTutuWawa 2022-12-09 20:41:53 +01:00
parent 797bf69856
commit fe1ba99b14
2 changed files with 17 additions and 10 deletions

View File

@ -5,16 +5,17 @@ abstract class OmemoEvent {}
/// Triggered when a ratchet has been modified /// Triggered when a ratchet has been modified
class RatchetModifiedEvent extends OmemoEvent { class RatchetModifiedEvent extends OmemoEvent {
RatchetModifiedEvent(this.jid, this.deviceId, this.ratchet, this.added);
RatchetModifiedEvent(this.jid, this.deviceId, this.ratchet);
final String jid; final String jid;
final int deviceId; final int deviceId;
final OmemoDoubleRatchet ratchet; 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. /// Triggered when a ratchet has been removed and should be removed from storage.
class RatchetRemovedEvent extends OmemoEvent { class RatchetRemovedEvent extends OmemoEvent {
RatchetRemovedEvent(this.jid, this.deviceId); RatchetRemovedEvent(this.jid, this.deviceId);
final String jid; final String jid;
final int deviceId; final int deviceId;
@ -22,7 +23,6 @@ class RatchetRemovedEvent extends OmemoEvent {
/// Triggered when the device map has been modified /// Triggered when the device map has been modified
class DeviceMapModifiedEvent extends OmemoEvent { class DeviceMapModifiedEvent extends OmemoEvent {
DeviceMapModifiedEvent(this.map); DeviceMapModifiedEvent(this.map);
final Map<String, List<int>> map; final Map<String, List<int>> map;
} }
@ -30,7 +30,6 @@ class DeviceMapModifiedEvent extends OmemoEvent {
/// Triggered by the OmemoSessionManager when our own device bundle was modified /// Triggered by the OmemoSessionManager when our own device bundle was modified
/// and thus should be republished. /// and thus should be republished.
class DeviceModifiedEvent extends OmemoEvent { class DeviceModifiedEvent extends OmemoEvent {
DeviceModifiedEvent(this.device); DeviceModifiedEvent(this.device);
final Device device; final Device device;
} }

View File

@ -28,7 +28,6 @@ import 'package:synchronized/synchronized.dart';
const omemoPayloadInfoString = 'OMEMO Payload'; const omemoPayloadInfoString = 'OMEMO Payload';
class OmemoSessionManager { class OmemoSessionManager {
OmemoSessionManager(this._device, this._deviceMap, this._ratchetMap, this._trustManager) OmemoSessionManager(this._device, this._deviceMap, this._ratchetMap, this._trustManager)
: _lock = Lock(), : _lock = Lock(),
_deviceLock = Lock(), _deviceLock = Lock(),
@ -136,7 +135,7 @@ class OmemoSessionManager {
_ratchetMap[key] = ratchet; _ratchetMap[key] = ratchet;
// Commit the 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 // 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.jid,
mapKey.deviceId, mapKey.deviceId,
oldRatchet, oldRatchet,
false,
), ),
); );
}); });
@ -421,6 +421,7 @@ class OmemoSessionManager {
senderJid, senderJid,
senderDeviceId, senderDeviceId,
oldRatchet, oldRatchet,
false,
), ),
); );
@ -476,7 +477,14 @@ class OmemoSessionManager {
} }
// Commit the ratchet // Commit the ratchet
_eventStreamController.add(RatchetModifiedEvent(senderJid, senderDeviceId, ratchet)); _eventStreamController.add(
RatchetModifiedEvent(
senderJid,
senderDeviceId,
ratchet,
false,
),
);
try { try {
return _decryptAndVerifyHmac(ciphertext, keyAndHmac); return _decryptAndVerifyHmac(ciphertext, keyAndHmac);
@ -606,7 +614,7 @@ class OmemoSessionManager {
..acknowledged = true; ..acknowledged = true;
// Commit it // Commit it
_eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet)); _eventStreamController.add(RatchetModifiedEvent(jid, deviceId, ratchet, false));
}); });
} }