Focus the currently active project if there is one

(also consider your own projects in "most_active_projects")
This commit is contained in:
Conrad Irwin 2023-10-09 12:05:26 -06:00
parent 6084486dcd
commit abfb4490d5
2 changed files with 34 additions and 6 deletions

View file

@ -605,7 +605,7 @@ impl Room {
} }
/// Returns the most 'active' projects, defined as most people in the project /// 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 projects = HashMap::default();
let mut hosts = 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(); let mut pairs: Vec<(u64, usize)> = projects.into_iter().collect();
pairs.sort_by_key(|(_, count)| *count as i32); pairs.sort_by_key(|(_, count)| *count as i32);

View file

@ -4162,16 +4162,37 @@ async fn join_channel_internal(
active_call: &ModelHandle<ActiveCall>, active_call: &ModelHandle<ActiveCall>,
cx: &mut AsyncAppContext, cx: &mut AsyncAppContext,
) -> Result<bool> { ) -> 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 { 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.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 should_prompt {
if let Some(workspace) = requesting_window { if let Some(workspace) = requesting_window {
if let Some(window) = workspace.update(cx, |cx| cx.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; room.update(cx, |room, _| room.next_room_update()).await;
let task = room.update(cx, |room, cx| { 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)); return Some(join_remote_project(project, host, app_state.clone(), cx));
} }