Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and clean up our ambiguity handling #4218

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

poljar
Copy link
Contributor

@poljar poljar commented Nov 5, 2024

This is in preparation of some higher level user display name handling, thus the rename of our DisplayName type as well.

No functional changes here.

@poljar poljar requested a review from a team as a code owner November 5, 2024 15:22
@poljar poljar requested review from jmartinesp and removed request for a team November 5, 2024 15:22
@poljar poljar force-pushed the poljar/refactor-ambiguity-handling branch from fe8868b to 4c376a1 Compare November 5, 2024 15:34
Copy link

codecov bot commented Nov 5, 2024

Codecov Report

Attention: Patch coverage is 97.56098% with 1 line in your changes missing coverage. Please review.

Project coverage is 84.85%. Comparing base (8865e2f) to head (4c376a1).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk-base/src/rooms/mod.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4218      +/-   ##
==========================================
- Coverage   84.89%   84.85%   -0.04%     
==========================================
  Files         272      272              
  Lines       29167    29167              
==========================================
- Hits        24761    24750      -11     
- Misses       4406     4417      +11     

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

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!

Comment on lines +145 to +149
entry.insert(old.display_name.clone(), old.users);
}

if let Some(new) = new_map {
entry.insert(new.display_name, new.users);
entry.insert(new.display_name.clone(), new.users);
Copy link
Member

Choose a reason for hiding this comment

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

Are these two clones needed?

}
}

async fn get_users_with_display_name(
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 add a brief doc comment explaining what it does please?

Some(display_name.unwrap_or_else(|| event.user_id().localpart().to_owned()))
let Some(Ok(old_event)) = old_event.map(|r| r.deserialize()) else { return Ok(None) };

if matches!(old_event.membership(), Join | Invite) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we include Knock here too?

use MembershipState::*;

let old_event = if let Some(m) = changes.state.get(room_id).and_then(|events| {
events.get(&StateEventType::RoomMember)?.get(member_event.state_key().as_str())
events.get(&StateEventType::RoomMember)?.get(new_event.state_key().as_str())
Copy link
Member

Choose a reason for hiding this comment

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

Could we store new_event.state_key() into a local variable named user_id, and reuse it all over the place in this function? I think it would make reading this code much simpler.

// We don't allow other users to set the display name, so if we
// have a more trusted version of the display
// name use that.
// We don't allow other users to set the display name, so if we have a more
Copy link
Member

Choose a reason for hiding this comment

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

(Same question above for Join | Invite, do we need to add | Knock?)

})
}

async fn get(
Copy link
Member

Choose a reason for hiding this comment

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

While you're here, can you add a brief doc comment too please?

@@ -154,60 +154,76 @@ impl AmbiguityCache {
self.changes.entry(room_id.to_owned()).or_default().insert(event_id, change);
}

async fn get(
&mut self,
async fn get_old_display_name(
Copy link
Member

Choose a reason for hiding this comment

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

And doc comment here too please!

@bnjbvr bnjbvr removed the request for review from jmartinesp November 5, 2024 16:59
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.

2 participants