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);
|
MoxxyOmemoManager(OmemoSessionManager omemoState) : super(omemoState);
|
||||||
|
|
||||||
// TODO(PapaTutuWawa): Override the storage related methods
|
|
||||||
@override
|
@override
|
||||||
Future<void> commitRatchet(OmemoDoubleRatchet ratchet, String jid, int deviceId) async {
|
Future<void> commitRatchet(OmemoDoubleRatchet ratchet, String jid, int deviceId) async {
|
||||||
await GetIt.I.get<DatabaseService>().saveRatchet(
|
await GetIt.I.get<DatabaseService>().saveRatchet(
|
||||||
OmemoDoubleRatchetWrapper(ratchet, deviceId, jid),
|
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(),
|
MemoryBTBVTrustManager(),
|
||||||
);
|
);
|
||||||
|
|
||||||
final device = await omemoState.getDevice();
|
|
||||||
|
|
||||||
await _storage.write(key: _omemoStorageMarker, value: 'true');
|
await _storage.write(key: _omemoStorageMarker, value: 'true');
|
||||||
await _storage.write(
|
await commitDevice(await omemoState.getDevice());
|
||||||
key: _omemoStorageDevice,
|
await commitDeviceMap(<String, List<int>>{});
|
||||||
value: jsonEncode(await device.toJson()),
|
|
||||||
);
|
|
||||||
await _storage.write(
|
|
||||||
key: _omemoStorageDeviceMap,
|
|
||||||
value: '{}',
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
_log.info('OMEMO marker found. Restoring OMEMO state...');
|
_log.info('OMEMO marker found. Restoring OMEMO state...');
|
||||||
final deviceString = await _storage.read(key: _omemoStorageDevice);
|
final deviceString = await _storage.read(key: _omemoStorageDevice);
|
||||||
|
@ -111,6 +111,13 @@ class OmemoManager extends XmppManagerBase {
|
|||||||
omemoState.eventStream.listen((event) async {
|
omemoState.eventStream.listen((event) async {
|
||||||
if (event is RatchetModifiedEvent) {
|
if (event is RatchetModifiedEvent) {
|
||||||
await commitRatchet(event.ratchet, event.jid, event.deviceId);
|
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
|
@visibleForOverriding
|
||||||
Future<void> commitRatchet(OmemoDoubleRatchet ratchet, String jid, int deviceId) async {}
|
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
|
@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
|
/// 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
|
/// an attached payload, if [children] is not null, or an empty OMEMO message if
|
||||||
|
Loading…
Reference in New Issue
Block a user