From 3fb83950856e715de3b70b49e31c73639fcda38d Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 9 Feb 2023 12:05:07 -0500 Subject: [PATCH] Make things a bit more infallible --- crates/collab_ui/src/collab_titlebar_item.rs | 138 +++++++++---------- 1 file changed, 65 insertions(+), 73 deletions(-) diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rs index d4c667b1c4..d89bc51569 100644 --- a/crates/collab_ui/src/collab_titlebar_item.rs +++ b/crates/collab_ui/src/collab_titlebar_item.rs @@ -2,7 +2,7 @@ use crate::{ collaborator_list_popover, collaborator_list_popover::CollaboratorListPopover, contact_notification::ContactNotification, contacts_popover, ToggleScreenSharing, }; -use call::{ActiveCall, ParticipantLocation}; +use call::{ActiveCall, ParticipantLocation, Room}; use client::{proto::PeerId, Authenticate, ContactEventKind, User, UserStore}; use clock::ReplicaId; use contacts_popover::ContactsPopover; @@ -82,13 +82,13 @@ impl View for CollabTitlebarItem { .boxed(), ); - if ActiveCall::global(cx).read(cx).room().is_some() { + if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() { left_container.add_child(self.render_share_unshare_button(&workspace, &theme, cx)); left_container.add_child(self.render_toggle_collaborator_list_button(&theme, cx)); - } - left_container.add_children(self.render_current_user(&workspace, &theme, cx)); - left_container.add_children(self.render_collaborators(&workspace, &theme, cx)); + left_container.add_child(self.render_current_user(&workspace, &theme, cx)); + left_container.add_children(self.render_collaborators(&workspace, &theme, room, cx)); + } let mut right_container = Flex::row(); @@ -486,41 +486,37 @@ impl CollabTitlebarItem { &self, workspace: &ViewHandle, theme: &Theme, + room: ModelHandle, cx: &mut RenderContext, ) -> Vec { - let active_call = ActiveCall::global(cx); - if let Some(room) = active_call.read(cx).room().cloned() { - let project = workspace.read(cx).project().read(cx); - let mut participants = room - .read(cx) - .remote_participants() - .values() - .cloned() - .collect::>(); - participants.sort_by_key(|p| Some(project.collaborators().get(&p.peer_id)?.replica_id)); - participants - .into_iter() - .filter_map(|participant| { - let project = workspace.read(cx).project().read(cx); - let replica_id = project - .collaborators() - .get(&participant.peer_id) - .map(|collaborator| collaborator.replica_id); - let user = participant.user.clone(); - Some(self.render_face_pile( - &user, - replica_id, - participant.peer_id, - Some(participant.location), - workspace, - theme, - cx, - )) - }) - .collect() - } else { - Default::default() - } + let project = workspace.read(cx).project().read(cx); + let mut participants = room + .read(cx) + .remote_participants() + .values() + .cloned() + .collect::>(); + participants.sort_by_key(|p| Some(project.collaborators().get(&p.peer_id)?.replica_id)); + participants + .into_iter() + .filter_map(|participant| { + let project = workspace.read(cx).project().read(cx); + let replica_id = project + .collaborators() + .get(&participant.peer_id) + .map(|collaborator| collaborator.replica_id); + let user = participant.user.clone(); + Some(self.render_face_pile( + &user, + replica_id, + participant.peer_id, + Some(participant.location), + workspace, + theme, + cx, + )) + }) + .collect() } fn render_current_user( @@ -528,42 +524,38 @@ impl CollabTitlebarItem { workspace: &ViewHandle, theme: &Theme, cx: &mut RenderContext, - ) -> Option { - let user = workspace.read(cx).user_store().read(cx).current_user(); + ) -> ElementBox { + let user = workspace + .read(cx) + .user_store() + .read(cx) + .current_user() + .expect("Active call without user"); let replica_id = workspace.read(cx).project().read(cx).replica_id(); - let peer_id = workspace.read(cx).client().peer_id()?; - let status = *workspace.read(cx).client().status().borrow(); - if let Some(user) = user { - Some(self.render_face_pile( - &user, - Some(replica_id), - peer_id, - None, - workspace, - theme, - cx, - )) - } else if matches!(status, client::Status::UpgradeRequired) { - None - } else { - Some( - MouseEventHandler::::new(0, cx, |state, _| { - let style = theme - .workspace - .titlebar - .sign_in_prompt - .style_for(state, false); - Label::new("Sign in", style.text.clone()) - .contained() - .with_style(style.container) - .boxed() - }) - .on_click(MouseButton::Left, |_, cx| cx.dispatch_action(Authenticate)) - .with_cursor_style(CursorStyle::PointingHand) - .aligned() - .boxed(), - ) - } + let peer_id = workspace + .read(cx) + .client() + .peer_id() + .expect("Active call without peer id"); + self.render_face_pile(&user, Some(replica_id), peer_id, None, workspace, theme, cx) + } + + fn render_authenticate(theme: &Theme, cx: &mut RenderContext) -> ElementBox { + MouseEventHandler::::new(0, cx, |state, _| { + let style = theme + .workspace + .titlebar + .sign_in_prompt + .style_for(state, false); + Label::new("Sign in", style.text.clone()) + .contained() + .with_style(style.container) + .boxed() + }) + .on_click(MouseButton::Left, |_, cx| cx.dispatch_action(Authenticate)) + .with_cursor_style(CursorStyle::PointingHand) + .aligned() + .boxed() } fn render_face_pile(