diff --git a/assets/icons/lock-8.svg b/assets/icons/lock-8.svg
new file mode 100644
index 0000000000..c98340b93a
--- /dev/null
+++ b/assets/icons/lock-8.svg
@@ -0,0 +1,3 @@
+
diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs
index 0fc0f97949..51da1f4c1c 100644
--- a/crates/client/src/client.rs
+++ b/crates/client/src/client.rs
@@ -67,17 +67,23 @@ pub struct Client {
peer: Arc,
http: Arc,
state: RwLock,
- authenticate:
+
+ #[cfg(any(test, feature = "test-support"))]
+ authenticate: RwLock<
Option Task>>>,
- establish_connection: Option<
- Box<
- dyn 'static
- + Send
- + Sync
- + Fn(
- &Credentials,
- &AsyncAppContext,
- ) -> Task>,
+ >,
+ #[cfg(any(test, feature = "test-support"))]
+ establish_connection: RwLock<
+ Option<
+ Box<
+ dyn 'static
+ + Send
+ + Sync
+ + Fn(
+ &Credentials,
+ &AsyncAppContext,
+ ) -> Task>,
+ >,
>,
>,
}
@@ -235,8 +241,11 @@ impl Client {
peer: Peer::new(),
http,
state: Default::default(),
- authenticate: None,
- establish_connection: None,
+
+ #[cfg(any(test, feature = "test-support"))]
+ authenticate: Default::default(),
+ #[cfg(any(test, feature = "test-support"))]
+ establish_connection: Default::default(),
})
}
@@ -260,23 +269,23 @@ impl Client {
}
#[cfg(any(test, feature = "test-support"))]
- pub fn override_authenticate(&mut self, authenticate: F) -> &mut Self
+ pub fn override_authenticate(&self, authenticate: F) -> &Self
where
F: 'static + Send + Sync + Fn(&AsyncAppContext) -> Task>,
{
- self.authenticate = Some(Box::new(authenticate));
+ *self.authenticate.write() = Some(Box::new(authenticate));
self
}
#[cfg(any(test, feature = "test-support"))]
- pub fn override_establish_connection(&mut self, connect: F) -> &mut Self
+ pub fn override_establish_connection(&self, connect: F) -> &Self
where
F: 'static
+ Send
+ Sync
+ Fn(&Credentials, &AsyncAppContext) -> Task>,
{
- self.establish_connection = Some(Box::new(connect));
+ *self.establish_connection.write() = Some(Box::new(connect));
self
}
@@ -755,11 +764,12 @@ impl Client {
}
fn authenticate(self: &Arc, cx: &AsyncAppContext) -> Task> {
- if let Some(callback) = self.authenticate.as_ref() {
- callback(cx)
- } else {
- self.authenticate_with_browser(cx)
+ #[cfg(any(test, feature = "test-support"))]
+ if let Some(callback) = self.authenticate.read().as_ref() {
+ return callback(cx);
}
+
+ self.authenticate_with_browser(cx)
}
fn establish_connection(
@@ -767,11 +777,12 @@ impl Client {
credentials: &Credentials,
cx: &AsyncAppContext,
) -> Task> {
- if let Some(callback) = self.establish_connection.as_ref() {
- callback(credentials, cx)
- } else {
- self.establish_websocket_connection(credentials, cx)
+ #[cfg(any(test, feature = "test-support"))]
+ if let Some(callback) = self.establish_connection.read().as_ref() {
+ return callback(credentials, cx);
}
+
+ self.establish_websocket_connection(credentials, cx)
}
fn establish_websocket_connection(
diff --git a/crates/client/src/test.rs b/crates/client/src/test.rs
index face7db16e..a809bd2769 100644
--- a/crates/client/src/test.rs
+++ b/crates/client/src/test.rs
@@ -28,7 +28,7 @@ struct FakeServerState {
impl FakeServer {
pub async fn for_client(
client_user_id: u64,
- client: &mut Arc,
+ client: &Arc,
cx: &TestAppContext,
) -> Self {
let server = Self {
@@ -38,8 +38,7 @@ impl FakeServer {
executor: cx.foreground(),
};
- Arc::get_mut(client)
- .unwrap()
+ client
.override_authenticate({
let state = Arc::downgrade(&server.state);
move |cx| {
diff --git a/crates/collab/src/integration_tests.rs b/crates/collab/src/integration_tests.rs
index 39964be671..2ba324eed8 100644
--- a/crates/collab/src/integration_tests.rs
+++ b/crates/collab/src/integration_tests.rs
@@ -30,7 +30,7 @@ use project::{
fs::{FakeFs, Fs as _},
search::SearchQuery,
worktree::WorktreeHandle,
- DiagnosticSummary, Project, ProjectPath, WorktreeId,
+ DiagnosticSummary, Project, ProjectPath, ProjectStore, WorktreeId,
};
use rand::prelude::*;
use rpc::PeerId;
@@ -174,9 +174,10 @@ async fn test_share_project(
project_id,
client_b2.client.clone(),
client_b2.user_store.clone(),
+ client_b2.project_store.clone(),
client_b2.language_registry.clone(),
FakeFs::new(cx_b2.background()),
- &mut cx_b2.to_async(),
+ cx_b2.to_async(),
)
.await
.unwrap();
@@ -310,16 +311,16 @@ async fn test_host_disconnect(
.unwrap();
// Request to join that project as client C
- let project_c = cx_c.spawn(|mut cx| async move {
+ let project_c = cx_c.spawn(|cx| {
Project::remote(
project_id,
client_c.client.clone(),
client_c.user_store.clone(),
+ client_c.project_store.clone(),
client_c.language_registry.clone(),
FakeFs::new(cx.background()),
- &mut cx,
+ cx,
)
- .await
});
deterministic.run_until_parked();
@@ -372,21 +373,16 @@ async fn test_decline_join_request(
let project_id = project_a.read_with(cx_a, |project, _| project.remote_id().unwrap());
// Request to join that project as client B
- let project_b = cx_b.spawn(|mut cx| {
- let client = client_b.client.clone();
- let user_store = client_b.user_store.clone();
- let language_registry = client_b.language_registry.clone();
- async move {
- Project::remote(
- project_id,
- client,
- user_store,
- language_registry,
- FakeFs::new(cx.background()),
- &mut cx,
- )
- .await
- }
+ let project_b = cx_b.spawn(|cx| {
+ Project::remote(
+ project_id,
+ client_b.client.clone(),
+ client_b.user_store.clone(),
+ client_b.project_store.clone(),
+ client_b.language_registry.clone(),
+ FakeFs::new(cx.background()),
+ cx,
+ )
});
deterministic.run_until_parked();
project_a.update(cx_a, |project, cx| {
@@ -398,20 +394,16 @@ async fn test_decline_join_request(
));
// Request to join the project again as client B
- let project_b = cx_b.spawn(|mut cx| {
- let client = client_b.client.clone();
- let user_store = client_b.user_store.clone();
- async move {
- Project::remote(
- project_id,
- client,
- user_store,
- client_b.language_registry.clone(),
- FakeFs::new(cx.background()),
- &mut cx,
- )
- .await
- }
+ let project_b = cx_b.spawn(|cx| {
+ Project::remote(
+ project_id,
+ client_b.client.clone(),
+ client_b.user_store.clone(),
+ client_b.project_store.clone(),
+ client_b.language_registry.clone(),
+ FakeFs::new(cx.background()),
+ cx,
+ )
});
// Close the project on the host
@@ -467,21 +459,16 @@ async fn test_cancel_join_request(
});
// Request to join that project as client B
- let project_b = cx_b.spawn(|mut cx| {
- let client = client_b.client.clone();
- let user_store = client_b.user_store.clone();
- let language_registry = client_b.language_registry.clone();
- async move {
- Project::remote(
- project_id,
- client,
- user_store,
- language_registry.clone(),
- FakeFs::new(cx.background()),
- &mut cx,
- )
- .await
- }
+ let project_b = cx_b.spawn(|cx| {
+ Project::remote(
+ project_id,
+ client_b.client.clone(),
+ client_b.user_store.clone(),
+ client_b.project_store.clone(),
+ client_b.language_registry.clone().clone(),
+ FakeFs::new(cx.background()),
+ cx,
+ )
});
deterministic.run_until_parked();
assert_eq!(
@@ -529,6 +516,7 @@ async fn test_private_projects(
false,
client_a.client.clone(),
client_a.user_store.clone(),
+ client_a.project_store.clone(),
client_a.language_registry.clone(),
fs.clone(),
cx,
@@ -4076,6 +4064,7 @@ async fn test_random_collaboration(
true,
host.client.clone(),
host.user_store.clone(),
+ host.project_store.clone(),
host_language_registry.clone(),
fs.clone(),
cx,
@@ -4311,9 +4300,10 @@ async fn test_random_collaboration(
host_project_id,
guest.client.clone(),
guest.user_store.clone(),
+ guest.project_store.clone(),
guest_lang_registry.clone(),
FakeFs::new(cx.background()),
- &mut guest_cx.to_async(),
+ guest_cx.to_async(),
)
.await
.unwrap();
@@ -4614,9 +4604,11 @@ impl TestServer {
});
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http, cx));
+ let project_store = cx.add_model(|_| ProjectStore::default());
let app_state = Arc::new(workspace::AppState {
client: client.clone(),
user_store: user_store.clone(),
+ project_store: project_store.clone(),
languages: Arc::new(LanguageRegistry::new(Task::ready(()))),
themes: ThemeRegistry::new((), cx.font_cache()),
fs: FakeFs::new(cx.background()),
@@ -4639,6 +4631,7 @@ impl TestServer {
peer_id,
username: name.to_string(),
user_store,
+ project_store,
language_registry: Arc::new(LanguageRegistry::test()),
project: Default::default(),
buffers: Default::default(),
@@ -4732,6 +4725,7 @@ struct TestClient {
username: String,
pub peer_id: PeerId,
pub user_store: ModelHandle,
+ pub project_store: ModelHandle,
language_registry: Arc,
project: Option>,
buffers: HashSet>,
@@ -4803,6 +4797,7 @@ impl TestClient {
true,
self.client.clone(),
self.user_store.clone(),
+ self.project_store.clone(),
self.language_registry.clone(),
fs,
cx,
@@ -4835,27 +4830,22 @@ impl TestClient {
.await;
let guest_user_id = self.user_id().unwrap();
let languages = host_project.read_with(host_cx, |project, _| project.languages().clone());
- let project_b = guest_cx.spawn(|mut cx| {
- let user_store = self.user_store.clone();
- let guest_client = self.client.clone();
- async move {
- Project::remote(
- host_project_id,
- guest_client,
- user_store.clone(),
- languages,
- FakeFs::new(cx.background()),
- &mut cx,
- )
- .await
- .unwrap()
- }
+ let project_b = guest_cx.spawn(|cx| {
+ Project::remote(
+ host_project_id,
+ self.client.clone(),
+ self.user_store.clone(),
+ self.project_store.clone(),
+ languages,
+ FakeFs::new(cx.background()),
+ cx,
+ )
});
host_cx.foreground().run_until_parked();
host_project.update(host_cx, |project, cx| {
project.respond_to_join_request(guest_user_id, true, cx)
});
- let project = project_b.await;
+ let project = project_b.await.unwrap();
self.project = Some(project.clone());
project
}
diff --git a/crates/contacts_panel/src/contacts_panel.rs b/crates/contacts_panel/src/contacts_panel.rs
index 13485e96f2..ffa3300e70 100644
--- a/crates/contacts_panel/src/contacts_panel.rs
+++ b/crates/contacts_panel/src/contacts_panel.rs
@@ -13,15 +13,16 @@ use gpui::{
impl_actions, impl_internal_actions,
platform::CursorStyle,
AppContext, ClipboardItem, Element, ElementBox, Entity, ModelHandle, MutableAppContext,
- RenderContext, Subscription, View, ViewContext, ViewHandle, WeakViewHandle,
+ RenderContext, Subscription, View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle,
};
use join_project_notification::JoinProjectNotification;
use menu::{Confirm, SelectNext, SelectPrev};
+use project::{Project, ProjectStore};
use serde::Deserialize;
use settings::Settings;
-use std::sync::Arc;
+use std::{ops::DerefMut, sync::Arc};
use theme::IconButton;
-use workspace::{sidebar::SidebarItem, JoinProject, Workspace};
+use workspace::{sidebar::SidebarItem, JoinProject, ToggleProjectPublic, Workspace};
impl_actions!(
contacts_panel,
@@ -37,13 +38,14 @@ enum Section {
Offline,
}
-#[derive(Clone, Debug)]
+#[derive(Clone)]
enum ContactEntry {
Header(Section),
IncomingRequest(Arc),
OutgoingRequest(Arc),
Contact(Arc),
- ContactProject(Arc, usize),
+ ContactProject(Arc, usize, Option>),
+ PrivateProject(WeakModelHandle),
}
#[derive(Clone)]
@@ -54,6 +56,7 @@ pub struct ContactsPanel {
match_candidates: Vec,
list_state: ListState,
user_store: ModelHandle,
+ project_store: ModelHandle,
filter_editor: ViewHandle,
collapsed_sections: Vec,
selection: Option,
@@ -89,6 +92,7 @@ pub fn init(cx: &mut MutableAppContext) {
impl ContactsPanel {
pub fn new(
user_store: ModelHandle,
+ project_store: ModelHandle,
workspace: WeakViewHandle,
cx: &mut ViewContext,
) -> Self {
@@ -148,93 +152,88 @@ impl ContactsPanel {
}
});
- cx.subscribe(&user_store, {
- let user_store = user_store.downgrade();
- move |_, _, event, cx| {
- if let Some((workspace, user_store)) =
- workspace.upgrade(cx).zip(user_store.upgrade(cx))
- {
- workspace.update(cx, |workspace, cx| match event {
- client::Event::Contact { user, kind } => match kind {
- ContactEventKind::Requested | ContactEventKind::Accepted => workspace
- .show_notification(user.id as usize, cx, |cx| {
- cx.add_view(|cx| {
- ContactNotification::new(
- user.clone(),
- *kind,
- user_store,
- cx,
- )
- })
- }),
- _ => {}
- },
- _ => {}
- });
- }
+ cx.observe(&project_store, |this, _, cx| this.update_entries(cx))
+ .detach();
- if let client::Event::ShowContacts = event {
- cx.emit(Event::Activate);
- }
+ cx.subscribe(&user_store, move |_, user_store, event, cx| {
+ if let Some(workspace) = workspace.upgrade(cx) {
+ workspace.update(cx, |workspace, cx| match event {
+ client::Event::Contact { user, kind } => match kind {
+ ContactEventKind::Requested | ContactEventKind::Accepted => workspace
+ .show_notification(user.id as usize, cx, |cx| {
+ cx.add_view(|cx| {
+ ContactNotification::new(user.clone(), *kind, user_store, cx)
+ })
+ }),
+ _ => {}
+ },
+ _ => {}
+ });
+ }
+
+ if let client::Event::ShowContacts = event {
+ cx.emit(Event::Activate);
}
})
.detach();
- let mut this = Self {
- list_state: ListState::new(0, Orientation::Top, 1000., cx, {
- move |this, ix, cx| {
- let theme = cx.global::().theme.clone();
- let theme = &theme.contacts_panel;
- let current_user_id =
- this.user_store.read(cx).current_user().map(|user| user.id);
- let is_selected = this.selection == Some(ix);
+ let list_state = ListState::new(0, Orientation::Top, 1000., cx, move |this, ix, cx| {
+ let theme = cx.global::().theme.clone();
+ let theme = &theme.contacts_panel;
+ let current_user_id = this.user_store.read(cx).current_user().map(|user| user.id);
+ let is_selected = this.selection == Some(ix);
- match &this.entries[ix] {
- ContactEntry::Header(section) => {
- let is_collapsed = this.collapsed_sections.contains(§ion);
- Self::render_header(*section, theme, is_selected, is_collapsed, cx)
- }
- ContactEntry::IncomingRequest(user) => Self::render_contact_request(
- user.clone(),
- this.user_store.clone(),
- theme,
- true,
- is_selected,
- cx,
- ),
- ContactEntry::OutgoingRequest(user) => Self::render_contact_request(
- user.clone(),
- this.user_store.clone(),
- theme,
- false,
- is_selected,
- cx,
- ),
- ContactEntry::Contact(contact) => {
- Self::render_contact(contact.clone(), theme, is_selected)
- }
- ContactEntry::ContactProject(contact, project_ix) => {
- let is_last_project_for_contact =
- this.entries.get(ix + 1).map_or(true, |next| {
- if let ContactEntry::ContactProject(next_contact, _) = next {
- next_contact.user.id != contact.user.id
- } else {
- true
- }
- });
- Self::render_contact_project(
- contact.clone(),
- current_user_id,
- *project_ix,
- theme,
- is_last_project_for_contact,
- is_selected,
- cx,
- )
- }
- }
+ match &this.entries[ix] {
+ ContactEntry::Header(section) => {
+ let is_collapsed = this.collapsed_sections.contains(§ion);
+ Self::render_header(*section, theme, is_selected, is_collapsed, cx)
}
- }),
+ ContactEntry::IncomingRequest(user) => Self::render_contact_request(
+ user.clone(),
+ this.user_store.clone(),
+ theme,
+ true,
+ is_selected,
+ cx,
+ ),
+ ContactEntry::OutgoingRequest(user) => Self::render_contact_request(
+ user.clone(),
+ this.user_store.clone(),
+ theme,
+ false,
+ is_selected,
+ cx,
+ ),
+ ContactEntry::Contact(contact) => {
+ Self::render_contact(&contact.user, theme, is_selected)
+ }
+ ContactEntry::ContactProject(contact, project_ix, _) => {
+ let is_last_project_for_contact =
+ this.entries.get(ix + 1).map_or(true, |next| {
+ if let ContactEntry::ContactProject(next_contact, _, _) = next {
+ next_contact.user.id != contact.user.id
+ } else {
+ true
+ }
+ });
+ Self::render_contact_project(
+ contact.clone(),
+ current_user_id,
+ *project_ix,
+ theme,
+ is_last_project_for_contact,
+ is_selected,
+ cx,
+ )
+ }
+ ContactEntry::PrivateProject(project) => {
+ Self::render_private_project(project.clone(), theme, is_selected, cx)
+ }
+ }
+ });
+
+ let mut this = Self {
+ list_state,
selection: None,
collapsed_sections: Default::default(),
entries: Default::default(),
@@ -242,6 +241,7 @@ impl ContactsPanel {
filter_editor,
_maintain_contacts: cx.observe(&user_store, |this, _, cx| this.update_entries(cx)),
user_store,
+ project_store,
};
this.update_entries(cx);
this
@@ -300,13 +300,9 @@ impl ContactsPanel {
.boxed()
}
- fn render_contact(
- contact: Arc,
- theme: &theme::ContactsPanel,
- is_selected: bool,
- ) -> ElementBox {
+ fn render_contact(user: &User, theme: &theme::ContactsPanel, is_selected: bool) -> ElementBox {
Flex::row()
- .with_children(contact.user.avatar.clone().map(|avatar| {
+ .with_children(user.avatar.clone().map(|avatar| {
Image::new(avatar)
.with_style(theme.contact_avatar)
.aligned()
@@ -315,7 +311,7 @@ impl ContactsPanel {
}))
.with_child(
Label::new(
- contact.user.github_login.clone(),
+ user.github_login.clone(),
theme.contact_username.text.clone(),
)
.contained()
@@ -446,6 +442,84 @@ impl ContactsPanel {
.boxed()
}
+ fn render_private_project(
+ project: WeakModelHandle,
+ theme: &theme::ContactsPanel,
+ is_selected: bool,
+ cx: &mut RenderContext,
+ ) -> ElementBox {
+ let project = if let Some(project) = project.upgrade(cx.deref_mut()) {
+ project
+ } else {
+ return Empty::new().boxed();
+ };
+
+ let host_avatar_height = theme
+ .contact_avatar
+ .width
+ .or(theme.contact_avatar.height)
+ .unwrap_or(0.);
+
+ enum LocalProject {}
+ enum TogglePublic {}
+
+ let project_id = project.id();
+ MouseEventHandler::new::(project_id, cx, |state, cx| {
+ let row = theme.project_row.style_for(state, is_selected);
+ let mut worktree_root_names = String::new();
+ let project = project.read(cx);
+ let is_public = project.is_public();
+ for tree in project.visible_worktrees(cx) {
+ if !worktree_root_names.is_empty() {
+ worktree_root_names.push_str(", ");
+ }
+ worktree_root_names.push_str(tree.read(cx).root_name());
+ }
+
+ Flex::row()
+ .with_child(
+ MouseEventHandler::new::(project_id, cx, |state, _| {
+ if is_public {
+ Empty::new().constrained()
+ } else {
+ render_icon_button(
+ theme.private_button.style_for(state, false),
+ "icons/lock-8.svg",
+ )
+ .aligned()
+ .constrained()
+ }
+ .with_width(host_avatar_height)
+ .boxed()
+ })
+ .with_cursor_style(if is_public {
+ CursorStyle::default()
+ } else {
+ CursorStyle::PointingHand
+ })
+ .on_click(move |_, _, cx| {
+ cx.dispatch_action(ToggleProjectPublic { project: None })
+ })
+ .boxed(),
+ )
+ .with_child(
+ Label::new(worktree_root_names, row.name.text.clone())
+ .aligned()
+ .left()
+ .contained()
+ .with_style(row.name.container)
+ .flex(1., false)
+ .boxed(),
+ )
+ .constrained()
+ .with_height(theme.row_height)
+ .contained()
+ .with_style(row.container)
+ .boxed()
+ })
+ .boxed()
+ }
+
fn render_contact_request(
user: Arc,
user_store: ModelHandle,
@@ -557,6 +631,7 @@ impl ContactsPanel {
fn update_entries(&mut self, cx: &mut ViewContext) {
let user_store = self.user_store.read(cx);
+ let project_store = self.project_store.read(cx);
let query = self.filter_editor.read(cx).text(cx);
let executor = cx.background().clone();
@@ -629,20 +704,37 @@ impl ContactsPanel {
}
}
+ let current_user = user_store.current_user();
+
let contacts = user_store.contacts();
if !contacts.is_empty() {
+ // Always put the current user first.
self.match_candidates.clear();
- self.match_candidates
- .extend(
- contacts
- .iter()
- .enumerate()
- .map(|(ix, contact)| StringMatchCandidate {
- id: ix,
- string: contact.user.github_login.clone(),
- char_bag: contact.user.github_login.chars().collect(),
- }),
- );
+ self.match_candidates.reserve(contacts.len());
+ self.match_candidates.push(StringMatchCandidate {
+ id: 0,
+ string: Default::default(),
+ char_bag: Default::default(),
+ });
+ for (ix, contact) in contacts.iter().enumerate() {
+ let candidate = StringMatchCandidate {
+ id: ix,
+ string: contact.user.github_login.clone(),
+ char_bag: contact.user.github_login.chars().collect(),
+ };
+ if current_user
+ .as_ref()
+ .map_or(false, |current_user| current_user.id == contact.user.id)
+ {
+ self.match_candidates[0] = candidate;
+ } else {
+ self.match_candidates.push(candidate);
+ }
+ }
+ if self.match_candidates[0].string.is_empty() {
+ self.match_candidates.remove(0);
+ }
+
let matches = executor.block(match_strings(
&self.match_candidates,
&query,
@@ -666,16 +758,60 @@ impl ContactsPanel {
for mat in matches {
let contact = &contacts[mat.candidate_id];
self.entries.push(ContactEntry::Contact(contact.clone()));
- self.entries
- .extend(contact.projects.iter().enumerate().filter_map(
- |(ix, project)| {
- if project.worktree_root_names.is_empty() {
+
+ let is_current_user = current_user
+ .as_ref()
+ .map_or(false, |user| user.id == contact.user.id);
+ if is_current_user {
+ let mut open_projects =
+ project_store.projects(cx).collect::>();
+ self.entries.extend(
+ contact.projects.iter().enumerate().filter_map(
+ |(ix, project)| {
+ let open_project = open_projects
+ .iter()
+ .position(|p| {
+ p.read(cx).remote_id() == Some(project.id)
+ })
+ .map(|ix| open_projects.remove(ix).downgrade());
+ if project.worktree_root_names.is_empty() {
+ None
+ } else {
+ Some(ContactEntry::ContactProject(
+ contact.clone(),
+ ix,
+ open_project,
+ ))
+ }
+ },
+ ),
+ );
+ self.entries.extend(open_projects.into_iter().filter_map(
+ |project| {
+ if project.read(cx).visible_worktrees(cx).next().is_none() {
None
} else {
- Some(ContactEntry::ContactProject(contact.clone(), ix))
+ Some(ContactEntry::PrivateProject(project.downgrade()))
}
},
));
+ } else {
+ self.entries.extend(
+ contact.projects.iter().enumerate().filter_map(
+ |(ix, project)| {
+ if project.worktree_root_names.is_empty() {
+ None
+ } else {
+ Some(ContactEntry::ContactProject(
+ contact.clone(),
+ ix,
+ None,
+ ))
+ }
+ },
+ ),
+ );
+ }
}
}
}
@@ -757,11 +893,18 @@ impl ContactsPanel {
let section = *section;
self.toggle_expanded(&ToggleExpanded(section), cx);
}
- ContactEntry::ContactProject(contact, project_index) => cx
- .dispatch_global_action(JoinProject {
- contact: contact.clone(),
- project_index: *project_index,
- }),
+ ContactEntry::ContactProject(contact, project_index, open_project) => {
+ if let Some(open_project) = open_project {
+ workspace::activate_workspace_for_project(cx, |_, cx| {
+ cx.model_id() == open_project.id()
+ });
+ } else {
+ cx.dispatch_global_action(JoinProject {
+ contact: contact.clone(),
+ project_index: *project_index,
+ })
+ }
+ }
_ => {}
}
}
@@ -952,11 +1095,16 @@ impl PartialEq for ContactEntry {
return contact_1.user.id == contact_2.user.id;
}
}
- ContactEntry::ContactProject(contact_1, ix_1) => {
- if let ContactEntry::ContactProject(contact_2, ix_2) = other {
+ ContactEntry::ContactProject(contact_1, ix_1, _) => {
+ if let ContactEntry::ContactProject(contact_2, ix_2, _) = other {
return contact_1.user.id == contact_2.user.id && ix_1 == ix_2;
}
}
+ ContactEntry::PrivateProject(project_1) => {
+ if let ContactEntry::PrivateProject(project_2) = other {
+ return project_1.id() == project_2.id();
+ }
+ }
}
false
}
@@ -965,20 +1113,55 @@ impl PartialEq for ContactEntry {
#[cfg(test)]
mod tests {
use super::*;
- use client::{proto, test::FakeServer, Client};
- use gpui::TestAppContext;
+ use client::{
+ proto,
+ test::{FakeHttpClient, FakeServer},
+ Client,
+ };
+ use gpui::{serde_json::json, TestAppContext};
use language::LanguageRegistry;
- use project::Project;
- use theme::ThemeRegistry;
- use workspace::AppState;
+ use project::{FakeFs, Project};
#[gpui::test]
async fn test_contact_panel(cx: &mut TestAppContext) {
- let (app_state, server) = init(cx).await;
- let project = Project::test(app_state.fs.clone(), [], cx).await;
- let workspace = cx.add_view(0, |cx| Workspace::new(project, cx));
+ Settings::test_async(cx);
+ let current_user_id = 100;
+
+ let languages = Arc::new(LanguageRegistry::test());
+ let http_client = FakeHttpClient::with_404_response();
+ let client = Client::new(http_client.clone());
+ let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
+ let project_store = cx.add_model(|_| ProjectStore::default());
+ let server = FakeServer::for_client(current_user_id, &client, &cx).await;
+ let fs = FakeFs::new(cx.background());
+ fs.insert_tree("/private_dir", json!({ "one.rs": "" }))
+ .await;
+ let project = cx.update(|cx| {
+ Project::local(
+ false,
+ client.clone(),
+ user_store.clone(),
+ project_store.clone(),
+ languages,
+ fs,
+ cx,
+ )
+ });
+ project
+ .update(cx, |project, cx| {
+ project.find_or_create_local_worktree("/private_dir", true, cx)
+ })
+ .await
+ .unwrap();
+
+ let workspace = cx.add_view(0, |cx| Workspace::new(project.clone(), cx));
let panel = cx.add_view(0, |cx| {
- ContactsPanel::new(app_state.user_store.clone(), workspace.downgrade(), cx)
+ ContactsPanel::new(
+ user_store.clone(),
+ project_store.clone(),
+ workspace.downgrade(),
+ cx,
+ )
});
let get_users_request = server.receive::().await.unwrap();
@@ -1001,6 +1184,11 @@ mod tests {
github_login: name.to_string(),
..Default::default()
})
+ .chain([proto::User {
+ id: current_user_id,
+ github_login: "the_current_user".to_string(),
+ ..Default::default()
+ }])
.collect(),
},
)
@@ -1039,6 +1227,16 @@ mod tests {
should_notify: false,
projects: vec![],
},
+ proto::Contact {
+ user_id: current_user_id,
+ online: true,
+ should_notify: false,
+ projects: vec![proto::ProjectMetadata {
+ id: 103,
+ worktree_root_names: vec!["dir3".to_string()],
+ guests: vec![3],
+ }],
+ },
],
..Default::default()
});
@@ -1052,6 +1250,9 @@ mod tests {
" incoming user_one",
" outgoing user_two",
"v Online",
+ " the_current_user",
+ " dir3",
+ " 🔒 private_dir",
" user_four",
" dir2",
" user_three",
@@ -1133,12 +1334,24 @@ mod tests {
ContactEntry::Contact(contact) => {
format!(" {}", contact.user.github_login)
}
- ContactEntry::ContactProject(contact, project_ix) => {
+ ContactEntry::ContactProject(contact, project_ix, _) => {
format!(
" {}",
contact.projects[*project_ix].worktree_root_names.join(", ")
)
}
+ ContactEntry::PrivateProject(project) => cx.read(|cx| {
+ format!(
+ " 🔒 {}",
+ project
+ .upgrade(cx)
+ .unwrap()
+ .read(cx)
+ .worktree_root_names(cx)
+ .collect::>()
+ .join(", ")
+ )
+ }),
};
if panel.selection == Some(ix) {
@@ -1150,28 +1363,4 @@ mod tests {
entries
})
}
-
- async fn init(cx: &mut TestAppContext) -> (Arc, FakeServer) {
- cx.update(|cx| cx.set_global(Settings::test(cx)));
- let themes = ThemeRegistry::new((), cx.font_cache());
- let fs = project::FakeFs::new(cx.background().clone());
- let languages = Arc::new(LanguageRegistry::test());
- let http_client = client::test::FakeHttpClient::with_404_response();
- let mut client = Client::new(http_client.clone());
- let server = FakeServer::for_client(100, &mut client, &cx).await;
- let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
-
- (
- Arc::new(AppState {
- languages,
- themes,
- client,
- user_store: user_store.clone(),
- fs,
- build_window_options: || Default::default(),
- initialize_workspace: |_, _, _| {},
- }),
- server,
- )
- }
}
diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs
index 19de98b3ce..bcdce61a05 100644
--- a/crates/gpui/src/app.rs
+++ b/crates/gpui/src/app.rs
@@ -4604,6 +4604,10 @@ impl WeakViewHandle {
self.view_id
}
+ pub fn window_id(&self) -> usize {
+ self.window_id
+ }
+
pub fn upgrade(&self, cx: &impl UpgradeViewHandle) -> Option> {
cx.upgrade_view_handle(self)
}
diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs
index 16a6481a43..10de12fbe1 100644
--- a/crates/gpui/src/platform.rs
+++ b/crates/gpui/src/platform.rs
@@ -147,6 +147,12 @@ pub struct AppVersion {
patch: usize,
}
+impl Default for CursorStyle {
+ fn default() -> Self {
+ Self::Arrow
+ }
+}
+
impl FromStr for AppVersion {
type Err = anyhow::Error;
diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs
index 58dc2ced20..9f8ba97ea8 100644
--- a/crates/project/src/project.rs
+++ b/crates/project/src/project.rs
@@ -59,6 +59,11 @@ pub trait Item: Entity {
fn entry_id(&self, cx: &AppContext) -> Option;
}
+#[derive(Default)]
+pub struct ProjectStore {
+ projects: Vec>,
+}
+
pub struct Project {
worktrees: Vec,
active_entry: Option,
@@ -75,6 +80,7 @@ pub struct Project {
next_entry_id: Arc,
next_diagnostic_group_id: usize,
user_store: ModelHandle,
+ project_store: ModelHandle,
fs: Arc,
client_state: ProjectClientState,
collaborators: HashMap,
@@ -121,6 +127,7 @@ enum ProjectClientState {
remote_id_tx: watch::Sender