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,41 +486,37 @@ 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); let project = workspace.read(cx).project().read(cx);
if let Some(room) = active_call.read(cx).room().cloned() { let mut participants = room
let project = workspace.read(cx).project().read(cx); .read(cx)
let mut participants = room .remote_participants()
.read(cx) .values()
.remote_participants() .cloned()
.values() .collect::<Vec<_>>();
.cloned() participants.sort_by_key(|p| Some(project.collaborators().get(&p.peer_id)?.replica_id));
.collect::<Vec<_>>(); participants
participants.sort_by_key(|p| Some(project.collaborators().get(&p.peer_id)?.replica_id)); .into_iter()
participants .filter_map(|participant| {
.into_iter() let project = workspace.read(cx).project().read(cx);
.filter_map(|participant| { let replica_id = project
let project = workspace.read(cx).project().read(cx); .collaborators()
let replica_id = project .get(&participant.peer_id)
.collaborators() .map(|collaborator| collaborator.replica_id);
.get(&participant.peer_id) let user = participant.user.clone();
.map(|collaborator| collaborator.replica_id); Some(self.render_face_pile(
let user = participant.user.clone(); &user,
Some(self.render_face_pile( replica_id,
&user, participant.peer_id,
replica_id, Some(participant.location),
participant.peer_id, workspace,
Some(participant.location), theme,
workspace, cx,
theme, ))
cx, })
)) .collect()
})
.collect()
} else {
Default::default()
}
} }
fn render_current_user( fn render_current_user(
@ -528,42 +524,38 @@ 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, MouseEventHandler::<Authenticate>::new(0, cx, |state, _| {
cx, let style = theme
)) .workspace
} else if matches!(status, client::Status::UpgradeRequired) { .titlebar
None .sign_in_prompt
} else { .style_for(state, false);
Some( Label::new("Sign in", style.text.clone())
MouseEventHandler::<Authenticate>::new(0, cx, |state, _| { .contained()
let style = theme .with_style(style.container)
.workspace .boxed()
.titlebar })
.sign_in_prompt .on_click(MouseButton::Left, |_, cx| cx.dispatch_action(Authenticate))
.style_for(state, false); .with_cursor_style(CursorStyle::PointingHand)
Label::new("Sign in", style.text.clone()) .aligned()
.contained() .boxed()
.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( fn render_face_pile(