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
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<String, List<int>> 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;
}

View File

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