service: Commit the device map and handle device changes
This commit is contained in:
parent
c1ff949346
commit
c1579cb106
@ -8,11 +8,20 @@ class MoxxyOmemoManager extends OmemoManager {
|
||||
|
||||
MoxxyOmemoManager(OmemoSessionManager omemoState) : super(omemoState);
|
||||
|
||||
// TODO(PapaTutuWawa): Override the storage related methods
|
||||
@override
|
||||
Future<void> commitRatchet(OmemoDoubleRatchet ratchet, String jid, int deviceId) async {
|
||||
await GetIt.I.get<DatabaseService>().saveRatchet(
|
||||
OmemoDoubleRatchetWrapper(ratchet, deviceId, jid),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> commitDeviceMap(Map<String, List<int>> map) async {
|
||||
await GetIt.I.get<OmemoService>().commitDeviceMap(map);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> commitDevice(Device device) async {
|
||||
await GetIt.I.get<OmemoService>().commitDevice(device);
|
||||
}
|
||||
}
|
||||
|
@ -40,17 +40,9 @@ class OmemoService {
|
||||
MemoryBTBVTrustManager(),
|
||||
);
|
||||
|
||||
final device = await omemoState.getDevice();
|
||||
|
||||
await _storage.write(key: _omemoStorageMarker, value: 'true');
|
||||
await _storage.write(
|
||||
key: _omemoStorageDevice,
|
||||
value: jsonEncode(await device.toJson()),
|
||||
);
|
||||
await _storage.write(
|
||||
key: _omemoStorageDeviceMap,
|
||||
value: '{}',
|
||||
);
|
||||
await commitDevice(await omemoState.getDevice());
|
||||
await commitDeviceMap(<String, List<int>>{});
|
||||
} else {
|
||||
_log.info('OMEMO marker found. Restoring OMEMO state...');
|
||||
final deviceString = await _storage.read(key: _omemoStorageDevice);
|
||||
|
@ -111,6 +111,13 @@ class OmemoManager extends XmppManagerBase {
|
||||
omemoState.eventStream.listen((event) async {
|
||||
if (event is RatchetModifiedEvent) {
|
||||
await commitRatchet(event.ratchet, event.jid, event.deviceId);
|
||||
} else if (event is DeviceMapModifiedEvent) {
|
||||
await commitDeviceMap(event.map);
|
||||
} else if (event is DeviceModifiedEvent) {
|
||||
await commitDevice(event.device);
|
||||
|
||||
// Publish it
|
||||
await publishBundle(await event.device.toBundle());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -177,11 +184,13 @@ class OmemoManager extends XmppManagerBase {
|
||||
@visibleForOverriding
|
||||
Future<void> commitRatchet(OmemoDoubleRatchet ratchet, String jid, int deviceId) async {}
|
||||
|
||||
/// Commit the session manager to storage, if wanted.
|
||||
/// Commit the session manager's device map to storage, if wanted.
|
||||
@visibleForOverriding
|
||||
Future<void> commitState() async {}
|
||||
Future<void> commitDeviceMap(Map<String, List<int>> map) async {}
|
||||
|
||||
/// Parses
|
||||
/// Commit the device to storage, if wanted.
|
||||
@visibleForOverriding
|
||||
Future<void> commitDevice(Device device) async {}
|
||||
|
||||
/// Encrypt [children] using OMEMO. This either produces an <encrypted /> element with
|
||||
/// an attached payload, if [children] is not null, or an empty OMEMO message if
|
||||
|
Loading…
Reference in New Issue
Block a user