crypto: Allow devices to be deleted from the crypto store.
This commit is contained in:
parent
877b880ded
commit
cb6e43b340
4 changed files with 26 additions and 2 deletions
|
@ -427,12 +427,13 @@ impl OlmMachine {
|
|||
for device_id in deleted_devices {
|
||||
if let Some(device) = stored_devices.get(device_id) {
|
||||
device.mark_as_deleted();
|
||||
// TODO change this to a delete device.
|
||||
self.store.save_device(device).await?;
|
||||
// TODO change this to a bulk deletion.
|
||||
self.store.delete_device(device).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO change this to a bulk operation.
|
||||
for device in &changed_devices {
|
||||
self.store.save_device(device.clone()).await?;
|
||||
}
|
||||
|
|
|
@ -88,6 +88,11 @@ impl CryptoStore for MemoryStore {
|
|||
Ok(self.devices.get(user_id, device_id))
|
||||
}
|
||||
|
||||
async fn delete_device(&self, device: Device) -> Result<()> {
|
||||
self.devices.remove(device.user_id(), device.device_id());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_user_devices(&self, user_id: &UserId) -> Result<UserDevices> {
|
||||
Ok(self.devices.user_devices(user_id))
|
||||
}
|
||||
|
@ -181,6 +186,13 @@ mod test {
|
|||
let loaded_device = user_devices.get(device.device_id()).unwrap();
|
||||
|
||||
assert_eq!(device, loaded_device);
|
||||
|
||||
store.delete_device(device.clone()).await.unwrap();
|
||||
assert!(store
|
||||
.get_device(device.user_id(), device.device_id())
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
|
|
@ -133,6 +133,13 @@ pub trait CryptoStore: Debug + Send + Sync {
|
|||
/// * `device` - The device that should be stored.
|
||||
async fn save_device(&self, device: Device) -> Result<()>;
|
||||
|
||||
/// Delete the given device from the store.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `device` - The device that should be stored.
|
||||
async fn delete_device(&self, device: Device) -> Result<()>;
|
||||
|
||||
/// Get the device for the given user with the given device id.
|
||||
///
|
||||
/// # Arguments
|
||||
|
|
|
@ -613,6 +613,10 @@ impl CryptoStore for SqliteStore {
|
|||
self.save_device_helper(device).await
|
||||
}
|
||||
|
||||
async fn delete_device(&self, device: Device) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn get_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<Option<Device>> {
|
||||
Ok(self.devices.get(user_id, device_id))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue