diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 4b160c78..3c8765df 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -1219,7 +1219,7 @@ impl OlmMachine { /// /// Returns true if the user was queued up for a key query, false otherwise. pub async fn mark_user_as_changed(&self, user_id: &UserId) -> StoreResult { - if self.store.read().await.tracked_users().contains(user_id) { + if self.store.read().await.is_user_tracked(user_id) { self.store .write() .await @@ -1250,7 +1250,7 @@ impl OlmMachine { I: IntoIterator, { for user in users { - if self.store.read().await.tracked_users().contains(user) { + if self.store.read().await.is_user_tracked(user) { continue; } diff --git a/matrix_sdk_crypto/src/store/memorystore.rs b/matrix_sdk_crypto/src/store/memorystore.rs index 1149766d..c8a9b7be 100644 --- a/matrix_sdk_crypto/src/store/memorystore.rs +++ b/matrix_sdk_crypto/src/store/memorystore.rs @@ -83,14 +83,14 @@ impl CryptoStore for MemoryStore { .get(room_id, sender_key, session_id)) } - fn tracked_users(&self) -> &HashSet { - &self.tracked_users - } - fn users_for_key_query(&self) -> &HashSet { &self.users_for_key_query } + fn is_user_tracked(&self, user_id: &UserId) -> bool { + self.tracked_users.contains(user_id) + } + async fn update_tracked_user(&mut self, user: &UserId, dirty: bool) -> Result { if dirty { self.users_for_key_query.insert(user.clone()); @@ -228,8 +228,6 @@ mod test { .await .unwrap()); - let tracked_users = store.tracked_users(); - - let _ = tracked_users.contains(device.user_id()); + assert!(store.is_user_tracked(device.user_id())); } } diff --git a/matrix_sdk_crypto/src/store/mod.rs b/matrix_sdk_crypto/src/store/mod.rs index 0f2dca0d..2a1814c2 100644 --- a/matrix_sdk_crypto/src/store/mod.rs +++ b/matrix_sdk_crypto/src/store/mod.rs @@ -143,8 +143,8 @@ pub trait CryptoStore: Debug { session_id: &str, ) -> Result>; - /// Get the set of tracked users. - fn tracked_users(&self) -> &HashSet; + /// Is the given user already tracked. + fn is_user_tracked(&self, user_id: &UserId) -> bool; /// Set of users that we need to query keys for. This is a subset of /// the tracked users. diff --git a/matrix_sdk_crypto/src/store/sqlite.rs b/matrix_sdk_crypto/src/store/sqlite.rs index b0cbdd0f..65c10a99 100644 --- a/matrix_sdk_crypto/src/store/sqlite.rs +++ b/matrix_sdk_crypto/src/store/sqlite.rs @@ -818,8 +818,8 @@ impl CryptoStore for SqliteStore { .get(room_id, sender_key, session_id)) } - fn tracked_users(&self) -> &HashSet { - &self.tracked_users + fn is_user_tracked(&self, user_id: &UserId) -> bool { + self.tracked_users.contains(user_id) } fn users_for_key_query(&self) -> &HashSet { @@ -1200,9 +1200,7 @@ mod test { .await .unwrap()); - let tracked_users = store.tracked_users(); - - assert!(tracked_users.contains(device.user_id())); + assert!(store.is_user_tracked(device.user_id())); assert!(!store.users_for_key_query().contains(device.user_id())); assert!(!store .update_tracked_user(device.user_id(), true) @@ -1217,8 +1215,7 @@ mod test { store.load_account().await.unwrap(); - let tracked_users = store.tracked_users(); - assert!(tracked_users.contains(device.user_id())); + assert!(store.is_user_tracked(device.user_id())); assert!(store.users_for_key_query().contains(device.user_id())); store