From 376aa1235f55b6fa185ccea906a98fbc212204aa Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 3 May 2023 10:37:57 +0200 Subject: [PATCH] Fix "IncomingCallNotification was dropped" error when accepting a call This was caused by accepting the call, which caused the notification to be removed. When `active_call.accept_incoming()` finally completed, we would try to get the app state from it in order to join the project, but couldn't becuase the view would have already been dropped. This commit fixes the bug by capturing a weak handle to the app state when accepting the call as opposed to trying to read it from the view when the accept completes. --- .../src/incoming_call_notification.rs | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/crates/collab_ui/src/incoming_call_notification.rs b/crates/collab_ui/src/incoming_call_notification.rs index 2e3048a4f8..35484b3309 100644 --- a/crates/collab_ui/src/incoming_call_notification.rs +++ b/crates/collab_ui/src/incoming_call_notification.rs @@ -78,24 +78,26 @@ impl IncomingCallNotification { let join = active_call.update(cx, |active_call, cx| active_call.accept_incoming(cx)); let caller_user_id = self.call.calling_user.id; let initial_project_id = self.call.initial_project.as_ref().map(|project| project.id); - cx.spawn(|this, mut cx| async move { - join.await?; - if let Some(project_id) = initial_project_id { - this.update(&mut cx, |this, cx| { - if let Some(app_state) = this.app_state.upgrade() { - workspace::join_remote_project( - project_id, - caller_user_id, - app_state, - cx, - ) - .detach_and_log_err(cx); - } - })?; - } - anyhow::Ok(()) - }) - .detach_and_log_err(cx); + let app_state = self.app_state.clone(); + cx.app_context() + .spawn(|mut cx| async move { + join.await?; + if let Some(project_id) = initial_project_id { + cx.update(|cx| { + if let Some(app_state) = app_state.upgrade() { + workspace::join_remote_project( + project_id, + caller_user_id, + app_state, + cx, + ) + .detach_and_log_err(cx); + } + }); + } + anyhow::Ok(()) + }) + .detach_and_log_err(cx); } else { active_call.update(cx, |active_call, _| { active_call.decline_incoming().log_err();