Set location on ActiveCall even before there's a room

We will automatically call `Room::set_location` once a room has been
assigned.
This commit is contained in:
Antonio Scandurra 2022-10-24 15:03:26 +02:00
parent 874a3605f8
commit 9860dbbbea
5 changed files with 80 additions and 53 deletions

View file

@ -120,19 +120,15 @@ impl CollabTitlebarItem {
}
fn window_activation_changed(&mut self, active: bool, cx: &mut ViewContext<Self>) {
let workspace = self.workspace.upgrade(cx);
let room = ActiveCall::global(cx).read(cx).room().cloned();
if let Some((workspace, room)) = workspace.zip(room) {
let workspace = workspace.read(cx);
if let Some(workspace) = self.workspace.upgrade(cx) {
let project = if active {
Some(workspace.project().clone())
Some(workspace.read(cx).project().clone())
} else {
None
};
room.update(cx, |room, cx| {
room.set_location(project.as_ref(), cx)
.detach_and_log_err(cx);
});
ActiveCall::global(cx)
.update(cx, |call, cx| call.set_location(project.as_ref(), cx))
.detach_and_log_err(cx);
}
}

View file

@ -1162,25 +1162,11 @@ impl ContactList {
fn call(&mut self, action: &Call, cx: &mut ViewContext<Self>) {
let recipient_user_id = action.recipient_user_id;
let initial_project = action.initial_project.clone();
let window_id = cx.window_id();
let active_call = ActiveCall::global(cx);
cx.spawn_weak(|_, mut cx| async move {
active_call
.update(&mut cx, |active_call, cx| {
active_call.invite(recipient_user_id, initial_project.clone(), cx)
})
.await?;
if cx.update(|cx| cx.window_is_active(window_id)) {
active_call
.update(&mut cx, |call, cx| {
call.set_location(initial_project.as_ref(), cx)
})
.await?;
}
anyhow::Ok(())
})
.detach_and_log_err(cx);
ActiveCall::global(cx)
.update(cx, |call, cx| {
call.invite(recipient_user_id, initial_project.clone(), cx)
})
.detach_and_log_err(cx);
}
fn leave_call(&mut self, _: &LeaveCall, cx: &mut ViewContext<Self>) {