From 1304902cb40fe8b8b7bd0b5f8f07f18fc99c47fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 4 Nov 2024 15:03:02 +0100 Subject: [PATCH] refactor(base): Rename AmbiguityMap to DisplayNameUsers The ambiguity map tracks the users which are using a single display name, so let's reflect that in the name. --- .../src/store/ambiguity_map.rs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/matrix-sdk-base/src/store/ambiguity_map.rs b/crates/matrix-sdk-base/src/store/ambiguity_map.rs index 907ee7c3e..5eabfcd7d 100644 --- a/crates/matrix-sdk-base/src/store/ambiguity_map.rs +++ b/crates/matrix-sdk-base/src/store/ambiguity_map.rs @@ -39,13 +39,13 @@ pub(crate) struct AmbiguityCache { pub changes: BTreeMap>, } -#[derive(Debug)] -struct AmbiguityMap { +#[derive(Debug, Clone)] +struct DisplayNameUsers { display_name: String, users: BTreeSet, } -impl AmbiguityMap { +impl DisplayNameUsers { fn remove(&mut self, user_id: &UserId) -> Option { self.users.remove(user_id); @@ -105,6 +105,8 @@ impl AmbiguityCache { _ => false, }; + // If the user's display name didn't change, then there's nothing more to + // calculate here. if display_names_same { return Ok(()); } @@ -134,8 +136,8 @@ impl AmbiguityCache { fn update( &mut self, room_id: &RoomId, - old_map: Option, - new_map: Option, + old_map: Option, + new_map: Option, ) { let entry = self.cache.entry(room_id.to_owned()).or_default(); @@ -157,7 +159,7 @@ impl AmbiguityCache { changes: &StateChanges, room_id: &RoomId, member_event: &SyncRoomMemberEvent, - ) -> Result<(Option, Option)> { + ) -> Result<(Option, Option)> { use MembershipState::*; let old_event = if let Some(m) = changes.state.get(room_id).and_then(|events| { @@ -202,7 +204,10 @@ impl AmbiguityCache { self.store.get_users_with_display_name(room_id, old_name).await? }; - Some(AmbiguityMap { display_name: old_name.to_owned(), users: old_display_name_map }) + Some(DisplayNameUsers { + display_name: old_name.to_owned(), + users: old_display_name_map, + }) } else { None }; @@ -232,7 +237,7 @@ impl AmbiguityCache { self.store.get_users_with_display_name(room_id, new_display_name).await? }; - Some(AmbiguityMap { + Some(DisplayNameUsers { display_name: new_display_name.to_owned(), users: new_display_name_map, })