service: Commit the device map and handle device changes

This commit is contained in:
PapaTutuWawa 2022-09-10 20:57:09 +02:00
parent c1ff949346
commit c1579cb106
3 changed files with 24 additions and 14 deletions

View File

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

View File

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

View File

@ -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