Make following more good

Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Conrad Irwin 2023-09-29 17:59:19 -06:00
parent 1cfc2f0c07
commit 92bb9a5fdc
6 changed files with 1263 additions and 1127 deletions

View file

@ -4,6 +4,7 @@ use gpui::{ModelHandle, TestAppContext};
mod channel_buffer_tests; mod channel_buffer_tests;
mod channel_message_tests; mod channel_message_tests;
mod channel_tests; mod channel_tests;
mod following_tests;
mod integration_tests; mod integration_tests;
mod random_channel_buffer_tests; mod random_channel_buffer_tests;
mod random_project_collaboration_tests; mod random_project_collaboration_tests;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1090,55 +1090,30 @@ impl CollabTitlebarItem {
}, },
); );
match (replica_id, location) { if Some(peer_id) == self_peer_id {
// If the user's location isn't known, do nothing. return content.into_any();
(_, None) => content.into_any(),
// If the user is not in this project, but is in another share project,
// join that project.
(None, Some(ParticipantLocation::SharedProject { project_id })) => content
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, this, cx| {
if let Some(workspace) = this.workspace.upgrade(cx) {
let app_state = workspace.read(cx).app_state().clone();
workspace::join_remote_project(project_id, user_id, app_state, cx)
.detach_and_log_err(cx);
}
})
.with_tooltip::<TitlebarParticipant>(
peer_id.as_u64() as usize,
format!("Follow {} into external project", user.github_login),
Some(Box::new(FollowNextCollaborator)),
theme.tooltip.clone(),
cx,
)
.into_any(),
// Otherwise, follow the user in the current window.
_ => content
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, item, cx| {
if let Some(workspace) = item.workspace.upgrade(cx) {
if let Some(task) = workspace
.update(cx, |workspace, cx| workspace.toggle_follow(peer_id, cx))
{
task.detach_and_log_err(cx);
}
}
})
.with_tooltip::<TitlebarParticipant>(
peer_id.as_u64() as usize,
if self_following {
format!("Unfollow {}", user.github_login)
} else {
format!("Follow {}", user.github_login)
},
Some(Box::new(FollowNextCollaborator)),
theme.tooltip.clone(),
cx,
)
.into_any(),
} }
content
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, this, cx| {
let Some(workspace) = this.workspace.upgrade(cx) else {
return;
};
if let Some(task) =
workspace.update(cx, |workspace, cx| workspace.follow(peer_id, cx))
{
task.detach_and_log_err(cx);
}
})
.with_tooltip::<TitlebarParticipant>(
peer_id.as_u64() as usize,
format!("Follow {}", user.github_login),
Some(Box::new(FollowNextCollaborator)),
theme.tooltip.clone(),
cx,
)
.into_any()
} }
fn location_style( fn location_style(

View file

@ -222,7 +222,7 @@ impl Member {
|_, _| { |_, _| {
Label::new( Label::new(
format!( format!(
"Follow {} on their active project", "Follow {} to their active project",
leader_user.github_login, leader_user.github_login,
), ),
theme theme

View file

@ -2529,6 +2529,7 @@ impl Workspace {
if let Some(prev_leader_id) = self.unfollow(&pane, cx) { if let Some(prev_leader_id) = self.unfollow(&pane, cx) {
if leader_id == prev_leader_id { if leader_id == prev_leader_id {
dbg!("oh no!");
return None; return None;
} }
} }
@ -2613,16 +2614,50 @@ impl Workspace {
leader_id: PeerId, leader_id: PeerId,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Option<Task<Result<()>>> { ) -> Option<Task<Result<()>>> {
let room = ActiveCall::global(cx).read(cx).room()?.read(cx);
let project = self.project.read(cx);
let Some(remote_participant) = room.remote_participant_for_peer_id(leader_id) else {
dbg!("no remote participant yet...");
return None;
};
let other_project_id = match remote_participant.location {
call::ParticipantLocation::External => None,
call::ParticipantLocation::UnsharedProject => None,
call::ParticipantLocation::SharedProject { project_id } => {
if Some(project_id) == project.remote_id() {
None
} else {
Some(project_id)
}
}
};
dbg!(other_project_id);
// if they are active in another project, follow there.
if let Some(project_id) = other_project_id {
let app_state = self.app_state.clone();
return Some(crate::join_remote_project(
project_id,
remote_participant.user.id,
app_state,
cx,
));
}
// if you're already following, find the right pane and focus it.
for (existing_leader_id, states_by_pane) in &mut self.follower_states_by_leader { for (existing_leader_id, states_by_pane) in &mut self.follower_states_by_leader {
if leader_id == *existing_leader_id { if leader_id == *existing_leader_id {
for (pane, _) in states_by_pane { for (pane, _) in states_by_pane {
dbg!("focusing pane");
cx.focus(pane); cx.focus(pane);
return None; return None;
} }
} }
} }
// not currently following, so follow. // Otherwise, follow.
self.toggle_follow(leader_id, cx) self.toggle_follow(leader_id, cx)
} }
@ -4214,6 +4249,7 @@ pub fn join_remote_project(
app_state: Arc<AppState>, app_state: Arc<AppState>,
cx: &mut AppContext, cx: &mut AppContext,
) -> Task<Result<()>> { ) -> Task<Result<()>> {
dbg!("huh??");
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
let existing_workspace = cx let existing_workspace = cx
.windows() .windows()
@ -4232,8 +4268,10 @@ pub fn join_remote_project(
.flatten(); .flatten();
let workspace = if let Some(existing_workspace) = existing_workspace { let workspace = if let Some(existing_workspace) = existing_workspace {
dbg!("huh");
existing_workspace existing_workspace
} else { } else {
dbg!("huh/");
let active_call = cx.read(ActiveCall::global); let active_call = cx.read(ActiveCall::global);
let room = active_call let room = active_call
.read_with(&cx, |call, _| call.room().cloned()) .read_with(&cx, |call, _| call.room().cloned())
@ -4249,6 +4287,7 @@ pub fn join_remote_project(
}) })
.await?; .await?;
dbg!("huh//");
let window_bounds_override = window_bounds_env_override(&cx); let window_bounds_override = window_bounds_env_override(&cx);
let window = cx.add_window( let window = cx.add_window(
(app_state.build_window_options)( (app_state.build_window_options)(
@ -4271,6 +4310,7 @@ pub fn join_remote_project(
workspace.downgrade() workspace.downgrade()
}; };
dbg!("huh///");
workspace.window().activate(&mut cx); workspace.window().activate(&mut cx);
cx.platform().activate(true); cx.platform().activate(true);
@ -4293,12 +4333,12 @@ pub fn join_remote_project(
Some(collaborator.peer_id) Some(collaborator.peer_id)
}); });
dbg!(follow_peer_id);
if let Some(follow_peer_id) = follow_peer_id { if let Some(follow_peer_id) = follow_peer_id {
if !workspace.is_being_followed(follow_peer_id) { workspace
workspace .follow(follow_peer_id, cx)
.toggle_follow(follow_peer_id, cx) .map(|follow| follow.detach_and_log_err(cx));
.map(|follow| follow.detach_and_log_err(cx));
}
} }
} }
})?; })?;