workspace: Do not prompt for hanging up current call when replacing last visible project (#36697)

Piotr Osiewicz created

This fixes a bug where in order to open a new project in a call (even if
it's not shared), you need to hang up.


Release Notes:

- N/A

Change summary

crates/workspace/src/workspace.rs | 50 +++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 17 deletions(-)

Detailed changes

crates/workspace/src/workspace.rs 🔗

@@ -2249,27 +2249,43 @@ impl Workspace {
             })?;
 
             if let Some(active_call) = active_call
-                && close_intent != CloseIntent::Quit
                 && workspace_count == 1
                 && active_call.read_with(cx, |call, _| call.room().is_some())?
             {
-                let answer = cx.update(|window, cx| {
-                    window.prompt(
-                        PromptLevel::Warning,
-                        "Do you want to leave the current call?",
-                        None,
-                        &["Close window and hang up", "Cancel"],
-                        cx,
-                    )
-                })?;
+                if close_intent == CloseIntent::CloseWindow {
+                    let answer = cx.update(|window, cx| {
+                        window.prompt(
+                            PromptLevel::Warning,
+                            "Do you want to leave the current call?",
+                            None,
+                            &["Close window and hang up", "Cancel"],
+                            cx,
+                        )
+                    })?;
 
-                if answer.await.log_err() == Some(1) {
-                    return anyhow::Ok(false);
-                } else {
-                    active_call
-                        .update(cx, |call, cx| call.hang_up(cx))?
-                        .await
-                        .log_err();
+                    if answer.await.log_err() == Some(1) {
+                        return anyhow::Ok(false);
+                    } else {
+                        active_call
+                            .update(cx, |call, cx| call.hang_up(cx))?
+                            .await
+                            .log_err();
+                    }
+                }
+                if close_intent == CloseIntent::ReplaceWindow {
+                    _ = active_call.update(cx, |this, cx| {
+                        let workspace = cx
+                            .windows()
+                            .iter()
+                            .filter_map(|window| window.downcast::<Workspace>())
+                            .next()
+                            .unwrap();
+                        let project = workspace.read(cx)?.project.clone();
+                        if project.read(cx).is_shared() {
+                            this.unshare_project(project, cx)?;
+                        }
+                        Ok::<_, anyhow::Error>(())
+                    })?;
                 }
             }