diff --git a/crates/matrix-sdk-base/src/store/ambiguity_map.rs b/crates/matrix-sdk-base/src/store/ambiguity_map.rs index b55955563f7..f02de1cc645 100644 --- a/crates/matrix-sdk-base/src/store/ambiguity_map.rs +++ b/crates/matrix-sdk-base/src/store/ambiguity_map.rs @@ -32,13 +32,6 @@ use crate::{ store::StateStoreExt, }; -#[derive(Debug)] -pub(crate) struct AmbiguityCache { - pub store: Arc, - pub cache: BTreeMap>>, - pub changes: BTreeMap>, -} - /// A map of users that use a certain display name. #[derive(Debug, Clone)] struct DisplayNameUsers { @@ -81,6 +74,18 @@ impl DisplayNameUsers { } } +fn is_member_active(membership: &MembershipState) -> bool { + use MembershipState::*; + matches!(membership, Join | Invite | Knock) +} + +#[derive(Debug)] +pub(crate) struct AmbiguityCache { + pub store: Arc, + pub cache: BTreeMap>>, + pub changes: BTreeMap>, +} + impl AmbiguityCache { /// Create a new [`AmbiguityCache`] backed by the given state store. pub fn new(store: Arc) -> Self { @@ -172,8 +177,6 @@ impl AmbiguityCache { room_id: &RoomId, new_event: &SyncRoomMemberEvent, ) -> Result> { - use MembershipState::*; - let user_id = new_event.state_key(); let old_event = if let Some(m) = changes @@ -188,7 +191,7 @@ impl AmbiguityCache { let Some(Ok(old_event)) = old_event.map(|r| r.deserialize()) else { return Ok(None) }; - if matches!(old_event.membership(), Join | Invite) { + if is_member_active(old_event.membership()) { let display_name = if let Some(d) = changes .profiles .get(room_id) @@ -248,8 +251,6 @@ impl AmbiguityCache { room_id: &RoomId, member_event: &SyncRoomMemberEvent, ) -> Result<(Option, Option)> { - use MembershipState::*; - let old_display_name = self.get_old_display_name(changes, room_id, member_event).await?; let old_map = if let Some(old_name) = old_display_name.as_deref() { @@ -258,7 +259,7 @@ impl AmbiguityCache { None }; - let new_map = if matches!(member_event.membership(), Join | Invite) { + let new_map = if is_member_active(member_event.membership()) { let new = member_event .as_original() .and_then(|ev| ev.content.displayname.as_deref())