Small refactoring to simplify member_disambiguations.

master
Denis Kasak 2020-07-01 12:06:59 +02:00
parent 9af48920f6
commit 32bdcede0c
1 changed files with 4 additions and 10 deletions

View File

@ -427,7 +427,7 @@ impl Room {
/// ///
/// The `inclusive` parameter controls whether the passed member should be included in the /// The `inclusive` parameter controls whether the passed member should be included in the
/// list or not. /// list or not.
fn shares_displayname_with(&self, member: &RoomMember, inclusive: bool) -> Vec<UserId> { fn shares_displayname_with(&self, member: &RoomMember, inclusive: bool) -> Vec<RoomMember> {
let members = self let members = self
.invited_members .invited_members
.iter() .iter()
@ -449,7 +449,7 @@ impl Room {
}) })
// If not an inclusive search, do not consider the member for which we are disambiguating. // If not an inclusive search, do not consider the member for which we are disambiguating.
.filter(|(id, _)| inclusive || **id != member.user_id) .filter(|(id, _)| inclusive || **id != member.user_id)
.map(|(id, _)| id) .map(|(_, member)| member)
.cloned() .cloned()
.collect() .collect()
} }
@ -467,16 +467,10 @@ impl Room {
inclusive: bool, inclusive: bool,
) -> HashMap<UserId, String> { ) -> HashMap<UserId, String> {
let users_with_same_name = self.shares_displayname_with(member, inclusive); let users_with_same_name = self.shares_displayname_with(member, inclusive);
let disambiguate_with = |members: Vec<UserId>, f: fn(&RoomMember) -> String| { let disambiguate_with = |members: Vec<RoomMember>, f: fn(&RoomMember) -> String| {
members members
.into_iter() .into_iter()
.filter_map(|id| { .map(|ref m| (m.user_id.clone(), f(m)))
self.joined_members
.get(&id)
.or_else(|| self.invited_members.get(&id))
.map(f)
.map(|m| (id, m))
})
.collect::<HashMap<UserId, String>>() .collect::<HashMap<UserId, String>>()
}; };