Skip to content

Conversation

@multisme
Copy link
Contributor

@multisme multisme commented Oct 13, 2025

Verify if the membership is not Leave when checking if a name in a room is ambiguous.

Signed-off-by:
multi

Fix #5774

@multisme multisme requested a review from a team as a code owner October 13, 2025 20:22
@multisme multisme requested review from stefanceriu and removed request for a team October 13, 2025 20:22
@multisme
Copy link
Contributor Author

It's pretty straightforward but should I had some tests?

@multisme multisme force-pushed the fix_check_if_user_really_ambiguous branch from b1cd305 to 47488fd Compare October 13, 2025 20:24
@codecov
Copy link

codecov bot commented Oct 13, 2025

Codecov Report

❌ Patch coverage is 98.79518% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.46%. Comparing base (a4e68ba) to head (2892f60).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
crates/matrix-sdk-base/src/room/members.rs 98.79% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5780   +/-   ##
=======================================
  Coverage   88.45%   88.46%           
=======================================
  Files         360      360           
  Lines      100322   100400   +78     
  Branches   100322   100400   +78     
=======================================
+ Hits        88737    88816   +79     
+ Misses       7420     7417    -3     
- Partials     4165     4167    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 13, 2025

CodSpeed Performance Report

Merging #5780 will not alter performance

Comparing multisme:fix_check_if_user_really_ambiguous (2892f60) with main (a4e68ba)

Summary

✅ 50 untouched

.is_some_and(|s| is_display_name_ambiguous(&display_name, s));
let membership = event.membership();
let display_name_ambiguous = users_display_names.get(&display_name).is_some_and(|s| {
is_display_name_ambiguous(&display_name, s) && *membership != MembershipState::Leave
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we don't want to disambiguate the name of a left user, why is that? I see the AmbiguityCache has a concept of active members so what are we trying to achieve here?

Copy link
Contributor Author

@multisme multisme Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because of the spec. It only sees member with an join or an invite membership as needing disambiguation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code to follow more precisely the spec.

@multisme multisme marked this pull request as draft October 14, 2025 08:22
@multisme multisme marked this pull request as ready for review October 14, 2025 13:16
@multisme multisme requested a review from stefanceriu October 14, 2025 13:17
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch! Can you add a test please? Ideally it would show the case that's failing on main (but supposed to work), and that would be working with your patch now.

Comment on lines 220 to 221
is_display_name_ambiguous(&display_name, s)
&& (*membership == MembershipState::Join || *membership == MembershipState::Invite)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write the second part with a match statement, please? This will make it so that we explicitly handle all the membership cases, and we don't forget to think about handling it, would we have a new membership kind later on.

if !is_display_name_ambiguous(&display_name, s) {
  return false;
}

match *membership {
 // handle all variants explicitly here
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I will

@bnjbvr bnjbvr removed the request for review from stefanceriu October 14, 2025 13:35
@multisme multisme marked this pull request as draft October 14, 2025 18:49
@multisme multisme force-pushed the fix_check_if_user_really_ambiguous branch from 6314fbb to 7a93c57 Compare October 14, 2025 18:52
@multisme
Copy link
Contributor Author

@bnjbvr
I have a problem here. There is a test that is failing that should be failing

assert_eq!(room.get_member(me).await.unwrap().expect("Me user").display_name(), Some("Me"));
assert_eq!(
room.get_member(mewto).await.unwrap().expect("Mewto user").display_name(),
Some("Me")
);
assert!(room.get_member(me).await.unwrap().expect("Me user").name_ambiguous());
assert!(room.get_member(mewto).await.unwrap().expect("Mewto user").name_ambiguous());

Unless I misunderstood, the name should be here ambiguous and the test should on line 621 should not be failing. Should I make a new issue ?

@bnjbvr
Copy link
Member

bnjbvr commented Oct 15, 2025

It sounds like the code you've changed introduced a regression, so, no, we can't merge this as is and open a new issue. Instead, one should investigate the issue and attempt to fix it :)

@multisme
Copy link
Contributor Author

So i checked, and it seems that when using saving_changes to store the member events in MemoryStore, the HashMap display_names: HashMap<OwnedRoomId, HashMap<DisplayName, BTreeSet<OwnedUserId>>> is never updated unless you expressly do it. But this is the Hashmap used by is_the_display_name_ambiguous.
If this is not the behavior expected, I can make an issue and a PR for making sure that hashmap is populated, wait for it to get merged, and then finish this PR.

@multisme
Copy link
Contributor Author

@bnjbvr
So i checked, and it seems that when using saving_changes to store the member events in MemoryStore, the HashMap display_names: HashMap<OwnedRoomId, HashMap<DisplayName, BTreeSet<OwnedUserId>>> is never updated unless you expressly do it. But this is the Hashmap used by is_the_display_name_ambiguous.
If this is not the behavior expected, I can make an issue and a PR for making sure that hashmap is populated, wait for it to get merged, and then finish this PR.

@multisme
Copy link
Contributor Author

multisme commented Oct 15, 2025

I made a mistake anyway, I should check the membership of every RoomMember with the same displayname, I'm getting back into IT.

@multisme multisme force-pushed the fix_check_if_user_really_ambiguous branch from b932ac2 to 1f759a6 Compare October 16, 2025 12:28
@multisme multisme marked this pull request as ready for review October 16, 2025 13:18
@multisme multisme force-pushed the fix_check_if_user_really_ambiguous branch from 52fad95 to 2892f60 Compare October 17, 2025 08:43
@multisme multisme requested a review from bnjbvr October 17, 2025 09:32
@poljar poljar requested review from poljar and removed request for bnjbvr October 24, 2025 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Room member display names incorrectly marked as ambiguous

3 participants