mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-24 17:28:40 +00:00
Focus the currently active project if there is one
(also consider your own projects in "most_active_projects")
This commit is contained in:
parent
6084486dcd
commit
abfb4490d5
2 changed files with 34 additions and 6 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue