From 464e181f6636beb186bd9c48e2ae13014a483e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 10 Sep 2020 14:59:20 +0200 Subject: [PATCH] crypto: Add a method to get all group sessions from the store. --- matrix_sdk_crypto/src/store/caches.rs | 13 +++++++++++++ matrix_sdk_crypto/src/store/memorystore.rs | 4 ++++ matrix_sdk_crypto/src/store/mod.rs | 3 +++ matrix_sdk_crypto/src/store/sqlite.rs | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/matrix_sdk_crypto/src/store/caches.rs b/matrix_sdk_crypto/src/store/caches.rs index 91344257..cc56c100 100644 --- a/matrix_sdk_crypto/src/store/caches.rs +++ b/matrix_sdk_crypto/src/store/caches.rs @@ -106,6 +106,19 @@ impl GroupSessionStore { .is_none() } + /// Get all the group sessions the store knows about. + pub fn get_all(&self) -> Vec { + self.entries + .iter() + .flat_map(|d| { + d.value() + .values() + .flat_map(|t| t.values().cloned().collect::>()) + .collect::>() + }) + .collect() + } + /// Get a inbound group session from our store. /// /// # Arguments diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index ec4a5246..4de015bf 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -99,6 +99,10 @@ impl CryptoStore for MemoryStore { .get(room_id, sender_key, session_id)) } + async fn get_inbound_group_sessions(&self) -> Result> { + Ok(self.inbound_group_sessions.get_all()) + } + fn users_for_key_query(&self) -> HashSet { #[allow(clippy::map_clone)] self.users_for_key_query.iter().map(|u| u.clone()).collect() diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index 2efd7d29..88d2ec90 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -179,6 +179,9 @@ pub trait CryptoStore: Debug { session_id: &str, ) -> Result>; + /// Get all the inbound group sessions we have stored. + async fn get_inbound_group_sessions(&self) -> Result>; + /// Is the given user already tracked. fn is_user_tracked(&self, user_id: &UserId) -> bool; diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index e55bcb8b..91b2a339 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -1289,6 +1289,10 @@ impl CryptoStore for SqliteStore { .get(room_id, sender_key, session_id)) } + async fn get_inbound_group_sessions(&self) -> Result> { + Ok(self.inbound_group_sessions.get_all()) + } + fn is_user_tracked(&self, user_id: &UserId) -> bool { self.tracked_users.contains(user_id) }