Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Focus the currently active project if there is one
Conrad Irwinabfb4490d590
diff --git a/crates/call/src/room.rs b/crates/call/src/room.rsindex 5419e00f02e..b7aeee90e20 100644--- a/crates/call/src/room.rs+++ b/crates/call/src/room.rs@@ -605,7 +605,7 @@ impl Room {}/// Returns the most 'active' projects, defined as most people in the project- pub fn most_active_project(&self) -> Option<(u64, u64)> {+ pub fn most_active_project(&self, cx: &AppContext) -> Option<(u64, u64)> {let mut projects = HashMap::default();let mut hosts = HashMap::default();@@ -622,6 +622,13 @@ impl Room {}}+ if let Some(user) = self.user_store.read(cx).current_user() {+ for project in &self.local_participant.projects {+ *projects.entry(project.id).or_insert(0) += 1;+ hosts.insert(project.id, user.id);+ }+ }+let mut pairs: Vec<(u64, usize)> = projects.into_iter().collect();pairs.sort_by_key(|(_, count)| *count as i32);diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex 7773abc19cc..e690757af71 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -4162,16 +4162,37 @@ async fn join_channel_internal(active_call: &ModelHandle<ActiveCall>,cx: &mut AsyncAppContext,) -> Result<bool> {- let should_prompt = active_call.read_with(cx, |active_call, cx| {+ let (should_prompt, open_room) = active_call.read_with(cx, |active_call, cx| {let Some(room) = active_call.room().map(|room| room.read(cx)) else {- return false;+ return (false, None);};- room.is_sharing_project()+ let already_in_channel = room.channel_id() == Some(channel_id);+ let should_prompt = room.is_sharing_project()&& room.remote_participants().len() > 0- && room.channel_id() != Some(channel_id)+ && !already_in_channel;+ let open_room = if already_in_channel {+ active_call.room().cloned()+ } else {+ None+ };+ (should_prompt, open_room)});+ if let Some(room) = open_room {+ let task = room.update(cx, |room, cx| {+ if let Some((project, host)) = room.most_active_project(cx) {+ return Some(join_remote_project(project, host, app_state.clone(), cx));+ }++ None+ });+ if let Some(task) = task {+ task.await?;+ }+ return anyhow::Ok(true);+ }+if should_prompt {if let Some(workspace) = requesting_window {if let Some(window) = workspace.update(cx, |cx| cx.window()) {@@ -4228,7 +4249,7 @@ async fn join_channel_internal(room.update(cx, |room, _| room.next_room_update()).await;let task = room.update(cx, |room, cx| {- if let Some((project, host)) = room.most_active_project() {+ if let Some((project, host)) = room.most_active_project(cx) {return Some(join_remote_project(project, host, app_state.clone(), cx));}