From 4532a4db6588cf212ff0108caed36415923728f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 7 Nov 2024 15:07:27 +0100 Subject: [PATCH] feat(base): Consider knocked members to be part of the room for display name disambiguation --- .../src/store/ambiguity_map.rs | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) 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())