feat: Allow regerating a device's id
This commit is contained in:
parent
0a03483aaf
commit
73613e266f
@ -163,6 +163,23 @@ class Device {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a new device that is equal to this one with the exception that the new
|
||||||
|
/// device's id is a new number between 0 and 2**32 - 1.
|
||||||
|
@internal
|
||||||
|
Device withNewId() {
|
||||||
|
return Device(
|
||||||
|
jid,
|
||||||
|
generateRandom32BitNumber(),
|
||||||
|
ik,
|
||||||
|
spk,
|
||||||
|
spkId,
|
||||||
|
spkSignature,
|
||||||
|
oldSpk,
|
||||||
|
oldSpkId,
|
||||||
|
opks,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts this device into an OmemoBundle that could be used for publishing.
|
/// Converts this device into an OmemoBundle that could be used for publishing.
|
||||||
Future<OmemoBundle> toBundle() async {
|
Future<OmemoBundle> toBundle() async {
|
||||||
final encodedOpks = <int, String>{};
|
final encodedOpks = <int, String>{};
|
||||||
|
@ -463,6 +463,19 @@ class OmemoSessionManager {
|
|||||||
Future<void> regenerateDevice({ int opkAmount = 100 }) async {
|
Future<void> regenerateDevice({ int opkAmount = 100 }) async {
|
||||||
await _deviceLock.synchronized(() async {
|
await _deviceLock.synchronized(() async {
|
||||||
_device = await Device.generateNewDevice(_device.jid, opkAmount: opkAmount);
|
_device = await Device.generateNewDevice(_device.jid, opkAmount: opkAmount);
|
||||||
|
|
||||||
|
// Commit it
|
||||||
|
_eventStreamController.add(DeviceModifiedEvent(_device));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Make our device have a new identifier. Only useful before publishing it as a bundle
|
||||||
|
/// to make sure that our device has a id that is account unique.
|
||||||
|
Future<void> regenerateDeviceId() async {
|
||||||
|
await _deviceLock.synchronized(() async {
|
||||||
|
_device = _device.withNewId();
|
||||||
|
|
||||||
|
// Commit it
|
||||||
_eventStreamController.add(DeviceModifiedEvent(_device));
|
_eventStreamController.add(DeviceModifiedEvent(_device));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user