From cb58c499b317451742ea491261cdab25a9bf5ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 12 Apr 2021 13:47:38 +0200 Subject: [PATCH] crypto: Store that our outbound session was invalidated --- matrix_sdk/src/room/joined.rs | 2 +- matrix_sdk_base/src/client.rs | 9 ++++++--- matrix_sdk_crypto/src/machine.rs | 6 ++++-- .../src/session_manager/group_sessions.rs | 11 ++++++++--- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/matrix_sdk/src/room/joined.rs b/matrix_sdk/src/room/joined.rs index a7fd20d7..822f8fc4 100644 --- a/matrix_sdk/src/room/joined.rs +++ b/matrix_sdk/src/room/joined.rs @@ -310,7 +310,7 @@ impl Joined { self.client .base_client .invalidate_group_session(self.inner.room_id()) - .await; + .await?; return Err(r); } } diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index da0726e0..9e98489c 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -1184,12 +1184,15 @@ impl BaseClient { /// to invalidate. #[cfg(feature = "encryption")] #[cfg_attr(feature = "docs", doc(cfg(encryption)))] - pub async fn invalidate_group_session(&self, room_id: &RoomId) -> bool { + pub async fn invalidate_group_session( + &self, + room_id: &RoomId, + ) -> Result { let olm = self.olm.lock().await; match &*olm { - Some(o) => o.invalidate_group_session(room_id), - None => false, + Some(o) => o.invalidate_group_session(room_id).await, + None => Ok(false), } } diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 02324928..4bb83afd 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -672,8 +672,10 @@ impl OlmMachine { /// /// Returns true if a session was invalidated, false if there was no session /// to invalidate. - pub fn invalidate_group_session(&self, room_id: &RoomId) -> bool { - self.group_session_manager.invalidate_group_session(room_id) + pub async fn invalidate_group_session(&self, room_id: &RoomId) -> StoreResult { + self.group_session_manager + .invalidate_group_session(room_id) + .await } /// Get to-device requests to share a group session with users in a room. diff --git a/matrix_sdk_crypto/src/session_manager/group_sessions.rs b/matrix_sdk_crypto/src/session_manager/group_sessions.rs index 68af665a..649664a8 100644 --- a/matrix_sdk_crypto/src/session_manager/group_sessions.rs +++ b/matrix_sdk_crypto/src/session_manager/group_sessions.rs @@ -66,12 +66,17 @@ impl GroupSessionManager { } } - pub fn invalidate_group_session(&self, room_id: &RoomId) -> bool { + pub async fn invalidate_group_session(&self, room_id: &RoomId) -> StoreResult { if let Some(s) = self.outbound_group_sessions.get(room_id) { s.invalidate_session(); - true + + let mut changes = Changes::default(); + changes.outbound_group_sessions.push(s.clone()); + self.store.save_changes(changes).await?; + + Ok(true) } else { - false + Ok(false) } }