Make things a bit more infallible

This commit is contained in:
Julia 2023-02-09 12:05:07 -05:00
parent 4513c40993
commit 3fb8395085

View file

@ -2,7 +2,7 @@ use crate::{
collaborator_list_popover, collaborator_list_popover::CollaboratorListPopover, collaborator_list_popover, collaborator_list_popover::CollaboratorListPopover,
contact_notification::ContactNotification, contacts_popover, ToggleScreenSharing, contact_notification::ContactNotification, contacts_popover, ToggleScreenSharing,
}; };
use call::{ActiveCall, ParticipantLocation}; use call::{ActiveCall, ParticipantLocation, Room};
use client::{proto::PeerId, Authenticate, ContactEventKind, User, UserStore}; use client::{proto::PeerId, Authenticate, ContactEventKind, User, UserStore};
use clock::ReplicaId; use clock::ReplicaId;
use contacts_popover::ContactsPopover; use contacts_popover::ContactsPopover;
@ -82,13 +82,13 @@ impl View for CollabTitlebarItem {
.boxed(), .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_share_unshare_button(&workspace, &theme, cx));
left_container.add_child(self.render_toggle_collaborator_list_button(&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_child(self.render_current_user(&workspace, &theme, cx));
left_container.add_children(self.render_collaborators(&workspace, &theme, cx)); left_container.add_children(self.render_collaborators(&workspace, &theme, room, cx));
}
let mut right_container = Flex::row(); let mut right_container = Flex::row();
@ -486,10 +486,9 @@ impl CollabTitlebarItem {
&self, &self,
workspace: &ViewHandle<Workspace>, workspace: &ViewHandle<Workspace>,
theme: &Theme, theme: &Theme,
room: ModelHandle<Room>,
cx: &mut RenderContext<Self>, cx: &mut RenderContext<Self>,
) -> Vec<ElementBox> { ) -> Vec<ElementBox> {
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 project = workspace.read(cx).project().read(cx);
let mut participants = room let mut participants = room
.read(cx) .read(cx)
@ -518,9 +517,6 @@ impl CollabTitlebarItem {
)) ))
}) })
.collect() .collect()
} else {
Default::default()
}
} }
fn render_current_user( fn render_current_user(
@ -528,25 +524,23 @@ impl CollabTitlebarItem {
workspace: &ViewHandle<Workspace>, workspace: &ViewHandle<Workspace>,
theme: &Theme, theme: &Theme,
cx: &mut RenderContext<Self>, cx: &mut RenderContext<Self>,
) -> Option<ElementBox> { ) -> ElementBox {
let user = workspace.read(cx).user_store().read(cx).current_user(); 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 replica_id = workspace.read(cx).project().read(cx).replica_id();
let peer_id = workspace.read(cx).client().peer_id()?; let peer_id = workspace
let status = *workspace.read(cx).client().status().borrow(); .read(cx)
if let Some(user) = user { .client()
Some(self.render_face_pile( .peer_id()
&user, .expect("Active call without peer id");
Some(replica_id), self.render_face_pile(&user, Some(replica_id), peer_id, None, workspace, theme, cx)
peer_id, }
None,
workspace, fn render_authenticate(theme: &Theme, cx: &mut RenderContext<Self>) -> ElementBox {
theme,
cx,
))
} else if matches!(status, client::Status::UpgradeRequired) {
None
} else {
Some(
MouseEventHandler::<Authenticate>::new(0, cx, |state, _| { MouseEventHandler::<Authenticate>::new(0, cx, |state, _| {
let style = theme let style = theme
.workspace .workspace
@ -561,9 +555,7 @@ impl CollabTitlebarItem {
.on_click(MouseButton::Left, |_, cx| cx.dispatch_action(Authenticate)) .on_click(MouseButton::Left, |_, cx| cx.dispatch_action(Authenticate))
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.aligned() .aligned()
.boxed(), .boxed()
)
}
} }
fn render_face_pile( fn render_face_pile(