Verify membership when test if name is ambiguous#5780
Verify membership when test if name is ambiguous#5780multisme wants to merge 9 commits intomatrix-org:mainfrom
Conversation
|
It's pretty straightforward but should I had some tests? |
b1cd305 to
47488fd
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5780 +/- ##
==========================================
+ Coverage 88.45% 88.47% +0.02%
==========================================
Files 360 360
Lines 100322 100400 +78
Branches 100322 100400 +78
==========================================
+ Hits 88737 88830 +93
+ Misses 7420 7403 -17
- Partials 4165 4167 +2 ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #5780 will not alter performanceComparing Summary
|
| .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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
It's because of the spec. It only sees member with an join or an invite membership as needing disambiguation
There was a problem hiding this comment.
I updated the code to follow more precisely the spec.
There was a problem hiding this comment.
Why not updating is_display_name_ambiguous to include this membership constraint? It seems to be really part of it.
bnjbvr
left a comment
There was a problem hiding this comment.
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.
| is_display_name_ambiguous(&display_name, s) | ||
| && (*membership == MembershipState::Join || *membership == MembershipState::Invite) |
There was a problem hiding this comment.
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
}There was a problem hiding this comment.
I think it's clearly worth adding this logic inside is_display_name_ambiguous.
6314fbb to
7a93c57
Compare
|
@bnjbvr matrix-rust-sdk/crates/matrix-sdk-base/src/room/members.rs Lines 615 to 622 in 7a93c57 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 ? |
|
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 :) |
|
So i checked, and it seems that when using saving_changes to store the member events in MemoryStore, the HashMap |
|
@bnjbvr |
|
I made a mistake anyway, I should check the membership of every RoomMember with the same displayname, I'm getting back into IT. |
b932ac2 to
1f759a6
Compare
52fad95 to
2892f60
Compare
|
@poljar Should I make an issue regarding this?
|
|
Just my 2 cents, but why don't we keep only the active members in the display names cache, rather than having unnecessary data in it, and then use a list of active members to filter it? |
|
tbh that would make sense, but that would be a breaking change. |
|
Why would this be a breaking change? Isn't this data used only internally when building a |
Hywan
left a comment
There was a problem hiding this comment.
Nice contribution, thank you.
I think we should merge the logic inside is_display_name_ambiguous to make less error-prone. What do you think?
| .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 |
There was a problem hiding this comment.
Why not updating is_display_name_ambiguous to include this membership constraint? It seems to be really part of it.
| is_display_name_ambiguous(&display_name, s) | ||
| && (*membership == MembershipState::Join || *membership == MembershipState::Invite) |
There was a problem hiding this comment.
I think it's clearly worth adding this logic inside is_display_name_ambiguous.
| let display_name = event.display_name(); | ||
| let membership = event.membership(); | ||
|
|
||
| println!("{:?} {:?}", users_display_names, &display_name); |
There was a problem hiding this comment.
Ok I will update is_display_name_ambiguous to take a MemberEvent instead of a string
|
I messed up the history big will force push because of it. |
cce393c to
2892f60
Compare
Hywan
left a comment
There was a problem hiding this comment.
My comments don't seem to be addressed. Is it on purpose :-)?
| .is_some_and(|s| is_display_name_ambiguous(&display_name, s)); | ||
|
|
||
| let display_name_ambiguous = users_display_names.get(&display_name).is_some_and(|s| { | ||
| // s.filter(|n| ) |
There was a problem hiding this comment.
No, taking care of that now.
There was a problem hiding this comment.
Ok I looked back into it, and the reason I didn't remove it was that I would need to make is_display_name_ambiguous accept the list of current active users, which imply a lot of changes in the matrix-sdk-base/src/store/ambiguity_map.rs, so I wanted to confirm before starting that work.
There was a problem hiding this comment.
You can as new commits and see where it goes. If it's too complex, we will take another path. Thanks for asking.
|
@Hywan I have created a new function get_active_users_display_name to replace get_users_display_name in the proper situations but in the case of IndexDB store, I have to either do two queries or write a migration. Writing a migration sounds cleaner but it feels like I should check before starting. |
Verify if the membership is not Leave when checking if a name in a room is ambiguous.
Signed-off-by:
multi
Fix #5774