Limit number of collaborators in local Facepiles (#4083)

Release Notes:

- Improves the rendering of the facepile in the titlebar with many
people
This commit is contained in:
Conrad Irwin 2024-01-17 08:34:56 -07:00 committed by GitHub
commit e2788f1f0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -477,7 +477,9 @@ impl CollabTitlebarItem {
return None; return None;
} }
const FACEPILE_LIMIT: usize = 3;
let followers = project_id.map_or(&[] as &[_], |id| room.followers_for(peer_id, id)); let followers = project_id.map_or(&[] as &[_], |id| room.followers_for(peer_id, id));
let extra_count = followers.len().saturating_sub(FACEPILE_LIMIT);
let pile = FacePile::default() let pile = FacePile::default()
.child( .child(
@ -499,18 +501,34 @@ impl CollabTitlebarItem {
) )
}), }),
) )
.children(followers.iter().filter_map(|follower_peer_id| { .children(
followers
.iter()
.take(FACEPILE_LIMIT)
.filter_map(|follower_peer_id| {
let follower = room let follower = room
.remote_participants() .remote_participants()
.values() .values()
.find_map(|p| (p.peer_id == *follower_peer_id).then_some(&p.user)) .find_map(|p| (p.peer_id == *follower_peer_id).then_some(&p.user))
.or_else(|| { .or_else(|| {
(self.client.peer_id() == Some(*follower_peer_id)).then_some(current_user) (self.client.peer_id() == Some(*follower_peer_id))
.then_some(current_user)
})? })?
.clone(); .clone();
Some(Avatar::new(follower.avatar_uri.clone())) Some(Avatar::new(follower.avatar_uri.clone()))
})); }),
)
.children(if extra_count > 0 {
Some(
div()
.ml_1()
.child(Label::new(format!("+{extra_count}")))
.into_any_element(),
)
} else {
None
});
Some(pile) Some(pile)
} }