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,
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,10 +486,9 @@ impl CollabTitlebarItem {
&self,
workspace: &ViewHandle<Workspace>,
theme: &Theme,
room: ModelHandle<Room>,
cx: &mut RenderContext<Self>,
) -> 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 mut participants = room
.read(cx)
@ -518,9 +517,6 @@ impl CollabTitlebarItem {
))
})
.collect()
} else {
Default::default()
}
}
fn render_current_user(
@ -528,25 +524,23 @@ impl CollabTitlebarItem {
workspace: &ViewHandle<Workspace>,
theme: &Theme,
cx: &mut RenderContext<Self>,
) -> Option<ElementBox> {
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(
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<Self>) -> ElementBox {
MouseEventHandler::<Authenticate>::new(0, cx, |state, _| {
let style = theme
.workspace
@ -561,9 +555,7 @@ impl CollabTitlebarItem {
.on_click(MouseButton::Left, |_, cx| cx.dispatch_action(Authenticate))
.with_cursor_style(CursorStyle::PointingHand)
.aligned()
.boxed(),
)
}
.boxed()
}
fn render_face_pile(