From 7adaa2046d84bf6460a8550cb03c5b0f92d23a2a Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 29 Sep 2023 15:08:25 -0700 Subject: [PATCH] Show current user as follower when following in unshared projects --- crates/collab_ui/src/collab_titlebar_item.rs | 76 +++++++++----------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rs index c1b3689aad..9f3b7d2f30 100644 --- a/crates/collab_ui/src/collab_titlebar_item.rs +++ b/crates/collab_ui/src/collab_titlebar_item.rs @@ -889,22 +889,17 @@ impl CollabTitlebarItem { let user_id = user.id; let project_id = workspace.read(cx).project().read(cx).remote_id(); let room = ActiveCall::global(cx).read(cx).room().cloned(); - let is_being_followed = workspace.read(cx).is_being_followed(peer_id); - let followed_by_self = room - .as_ref() - .and_then(|room| { - Some( - is_being_followed - && room - .read(cx) - .followers_for(peer_id, project_id?) - .iter() - .any(|&follower| { - Some(follower) == workspace.read(cx).client().peer_id() - }), - ) - }) - .unwrap_or(false); + let self_peer_id = workspace.read(cx).client().peer_id(); + let self_following = workspace.read(cx).is_being_followed(peer_id); + let self_following_initialized = self_following + && room.as_ref().map_or(false, |room| match project_id { + None => true, + Some(project_id) => room + .read(cx) + .followers_for(peer_id, project_id) + .iter() + .any(|&follower| Some(follower) == self_peer_id), + }); let leader_style = theme.titlebar.leader_avatar; let follower_style = theme.titlebar.follower_avatar; @@ -930,7 +925,7 @@ impl CollabTitlebarItem { .get(&user_id) .copied(); if let Some(participant_index) = participant_index { - if followed_by_self { + if self_following_initialized { let selection = theme .editor .selection_style_for_room_participant(participant_index.0) @@ -960,31 +955,14 @@ impl CollabTitlebarItem { let project_id = project_id?; let room = room?.read(cx); let followers = room.followers_for(peer_id, project_id); - - Some(followers.into_iter().flat_map(|&follower| { - let remote_participant = - room.remote_participant_for_peer_id(follower); - - let avatar = remote_participant - .and_then(|p| p.user.avatar.clone()) - .or_else(|| { - if follower - == workspace.read(cx).client().peer_id()? - { - workspace - .read(cx) - .user_store() - .read(cx) - .current_user()? - .avatar - .clone() - } else { - None - } - })?; - + Some(followers.into_iter().filter_map(|&follower| { + if Some(follower) == self_peer_id { + return None; + } + let participant = + room.remote_participant_for_peer_id(follower)?; Some(Self::render_face( - avatar.clone(), + participant.user.avatar.clone()?, follower_style, background_color, None, @@ -993,6 +971,18 @@ impl CollabTitlebarItem { })() .into_iter() .flatten(), + ) + .with_children( + self_following_initialized + .then(|| self.user_store.read(cx).current_user()) + .and_then(|user| { + Some(Self::render_face( + user?.avatar.clone()?, + follower_style, + background_color, + None, + )) + }), ); let mut container = face_pile @@ -1000,7 +990,7 @@ impl CollabTitlebarItem { .with_style(theme.titlebar.leader_selection); if let Some(participant_index) = participant_index { - if followed_by_self { + if self_following_initialized { let color = theme .editor .selection_style_for_room_participant(participant_index.0) @@ -1067,7 +1057,7 @@ impl CollabTitlebarItem { }) .with_tooltip::( peer_id.as_u64() as usize, - if is_being_followed { + if self_following { format!("Unfollow {}", user.github_login) } else { format!("Follow {}", user.github_login)