Abuse a closure instead of abusing options/iterators quite so much

This commit is contained in:
Julia 2023-02-04 01:30:24 -05:00
parent 58c41778e7
commit 33c265d3cf
2 changed files with 17 additions and 32 deletions

View file

@ -459,10 +459,10 @@ impl Room {
self.participant_user_ids.contains(&user_id) self.participant_user_ids.contains(&user_id)
} }
pub fn follows(&self, leader_id: PeerId) -> &[PeerId] { pub fn follows(&self, leader_id: PeerId) -> Option<&[PeerId]> {
self.follows_by_leader_id self.follows_by_leader_id
.get(&leader_id) .get(&leader_id)
.map_or(&[], |v| v.as_slice()) .map(|v| v.as_slice())
} }
async fn handle_room_updated( async fn handle_room_updated(

View file

@ -569,11 +569,6 @@ impl CollabTitlebarItem {
workspace.read(cx).is_following(peer_id) workspace.read(cx).is_following(peer_id)
}); });
let room = ActiveCall::global(cx).read(cx).room();
let get_followers = |leader_id: PeerId| -> &[PeerId] {
room.map_or(&[], |room| room.read(cx).follows(leader_id))
};
let mut avatar_style; let mut avatar_style;
if let Some((_, location)) = peer_id_and_location { if let Some((_, location)) = peer_id_and_location {
if let ParticipantLocation::SharedProject { project_id } = location { if let ParticipantLocation::SharedProject { project_id } = location {
@ -603,29 +598,19 @@ impl CollabTitlebarItem {
Flex::row() Flex::row()
.with_child(Self::render_face(avatar.clone(), avatar_style, theme)) .with_child(Self::render_face(avatar.clone(), avatar_style, theme))
.with_children( .with_children(
peer_id_and_location (|| {
.map(|(peer_id, _)| { let peer_id_and_location = peer_id_and_location?;
get_followers(peer_id) let peer_id = peer_id_and_location.0;
.into_iter()
.map(|&follower| { let room = ActiveCall::global(cx).read(cx).room()?.read(cx);
room.map(|room| { let followers = room.follows(peer_id)?;
room.read(cx)
.remote_participant_for_peer_id(follower) Some(followers.into_iter().flat_map(|&follower| {
.map(|participant| { let participant = room.remote_participant_for_peer_id(follower)?;
participant.user.avatar.as_ref().map(|avatar| { let avatar = participant.user.avatar.as_ref()?;
Self::render_face( Some(Self::render_face(avatar.clone(), avatar_style, theme))
avatar.clone(), }))
avatar_style, })()
theme,
)
})
})
.flatten()
})
.flatten()
})
.flatten()
})
.into_iter() .into_iter()
.flatten(), .flatten(),
) )