Rename project's 'public'/'private' flag to 'online'/'offline'

This commit is contained in:
Max Brunsfeld 2022-06-03 14:39:06 -07:00
parent b2aa831017
commit e18bc24989
4 changed files with 59 additions and 59 deletions

View file

@ -519,7 +519,7 @@ async fn test_private_projects(
.read_with(cx_b, |store, _| { store.contacts()[0].projects.is_empty() })); .read_with(cx_b, |store, _| { store.contacts()[0].projects.is_empty() }));
// The project is registered when it is made public. // The project is registered when it is made public.
project_a.update(cx_a, |project, cx| project.set_public(true, cx)); project_a.update(cx_a, |project, cx| project.set_online(true, cx));
deterministic.run_until_parked(); deterministic.run_until_parked();
assert!(project_a.read_with(cx_a, |project, _| project.remote_id().is_some())); assert!(project_a.read_with(cx_a, |project, _| project.remote_id().is_some()));
assert!(!client_b assert!(!client_b

View file

@ -45,7 +45,7 @@ enum ContactEntry {
OutgoingRequest(Arc<User>), OutgoingRequest(Arc<User>),
Contact(Arc<Contact>), Contact(Arc<Contact>),
ContactProject(Arc<Contact>, usize, Option<WeakModelHandle<Project>>), ContactProject(Arc<Contact>, usize, Option<WeakModelHandle<Project>>),
PrivateProject(WeakModelHandle<Project>), OfflineProject(WeakModelHandle<Project>),
} }
#[derive(Clone)] #[derive(Clone)]
@ -233,7 +233,7 @@ impl ContactsPanel {
cx, cx,
) )
} }
ContactEntry::PrivateProject(project) => Self::render_private_project( ContactEntry::OfflineProject(project) => Self::render_offline_project(
project.clone(), project.clone(),
&theme.contacts_panel, &theme.contacts_panel,
&theme.tooltip, &theme.tooltip,
@ -412,8 +412,8 @@ impl ContactsPanel {
.boxed(), .boxed(),
) )
.with_children(open_project.and_then(|open_project| { .with_children(open_project.and_then(|open_project| {
let is_becoming_private = !open_project.read(cx).is_public(); let is_going_offline = !open_project.read(cx).is_online();
if !mouse_state.hovered && !is_becoming_private { if !mouse_state.hovered && !is_going_offline {
return None; return None;
} }
@ -425,7 +425,7 @@ impl ContactsPanel {
*theme.private_button.style_for(state, false); *theme.private_button.style_for(state, false);
icon_style.container.background_color = icon_style.container.background_color =
row.container.background_color; row.container.background_color;
if is_becoming_private { if is_going_offline {
icon_style.color = theme.disabled_button.color; icon_style.color = theme.disabled_button.color;
} }
render_icon_button(&icon_style, "icons/lock-8.svg") render_icon_button(&icon_style, "icons/lock-8.svg")
@ -434,7 +434,7 @@ impl ContactsPanel {
}, },
); );
if is_becoming_private { if is_going_offline {
Some(button.boxed()) Some(button.boxed())
} else { } else {
Some( Some(
@ -447,7 +447,7 @@ impl ContactsPanel {
}) })
.with_tooltip( .with_tooltip(
project_id as usize, project_id as usize,
"Make project private".to_string(), "Take project offline".to_string(),
None, None,
tooltip_style.clone(), tooltip_style.clone(),
cx, cx,
@ -505,7 +505,7 @@ impl ContactsPanel {
.boxed() .boxed()
} }
fn render_private_project( fn render_offline_project(
project: WeakModelHandle<Project>, project: WeakModelHandle<Project>,
theme: &theme::ContactsPanel, theme: &theme::ContactsPanel,
tooltip_style: &TooltipStyle, tooltip_style: &TooltipStyle,
@ -532,7 +532,7 @@ impl ContactsPanel {
let row = theme.project_row.style_for(state, is_selected); let row = theme.project_row.style_for(state, is_selected);
let mut worktree_root_names = String::new(); let mut worktree_root_names = String::new();
let project_ = project.read(cx); let project_ = project.read(cx);
let is_becoming_public = project_.is_public(); let is_going_online = project_.is_online();
for tree in project_.visible_worktrees(cx) { for tree in project_.visible_worktrees(cx) {
if !worktree_root_names.is_empty() { if !worktree_root_names.is_empty() {
worktree_root_names.push_str(", "); worktree_root_names.push_str(", ");
@ -545,7 +545,7 @@ impl ContactsPanel {
let button = let button =
MouseEventHandler::new::<TogglePublic, _, _>(project_id, cx, |state, _| { MouseEventHandler::new::<TogglePublic, _, _>(project_id, cx, |state, _| {
let mut style = *theme.private_button.style_for(state, false); let mut style = *theme.private_button.style_for(state, false);
if is_becoming_public { if is_going_online {
style.color = theme.disabled_button.color; style.color = theme.disabled_button.color;
} }
render_icon_button(&style, "icons/lock-8.svg") render_icon_button(&style, "icons/lock-8.svg")
@ -555,7 +555,7 @@ impl ContactsPanel {
.boxed() .boxed()
}); });
if is_becoming_public { if is_going_online {
button.boxed() button.boxed()
} else { } else {
button button
@ -567,7 +567,7 @@ impl ContactsPanel {
}) })
.with_tooltip( .with_tooltip(
project_id, project_id,
"Make project public".to_string(), "Take project online".to_string(),
None, None,
tooltip_style.clone(), tooltip_style.clone(),
cx, cx,
@ -864,7 +864,7 @@ impl ContactsPanel {
if project.read(cx).visible_worktrees(cx).next().is_none() { if project.read(cx).visible_worktrees(cx).next().is_none() {
None None
} else { } else {
Some(ContactEntry::PrivateProject(project.downgrade())) Some(ContactEntry::OfflineProject(project.downgrade()))
} }
}, },
)); ));
@ -1173,8 +1173,8 @@ impl PartialEq for ContactEntry {
return contact_1.user.id == contact_2.user.id && ix_1 == ix_2; return contact_1.user.id == contact_2.user.id && ix_1 == ix_2;
} }
} }
ContactEntry::PrivateProject(project_1) => { ContactEntry::OfflineProject(project_1) => {
if let ContactEntry::PrivateProject(project_2) = other { if let ContactEntry::OfflineProject(project_2) = other {
return project_1.id() == project_2.id(); return project_1.id() == project_2.id();
} }
} }
@ -1351,7 +1351,7 @@ mod tests {
// Make a project public. It appears as loading, since the project // Make a project public. It appears as loading, since the project
// isn't yet visible to other contacts. // isn't yet visible to other contacts.
project.update(cx, |project, cx| project.set_public(true, cx)); project.update(cx, |project, cx| project.set_online(true, cx));
cx.foreground().run_until_parked(); cx.foreground().run_until_parked();
assert_eq!( assert_eq!(
cx.read(|cx| render_to_strings(&panel, cx)), cx.read(|cx| render_to_strings(&panel, cx)),
@ -1458,7 +1458,7 @@ mod tests {
); );
// Make the project private. It appears as loading. // Make the project private. It appears as loading.
project.update(cx, |project, cx| project.set_public(false, cx)); project.update(cx, |project, cx| project.set_online(false, cx));
cx.foreground().run_until_parked(); cx.foreground().run_until_parked();
assert_eq!( assert_eq!(
cx.read(|cx| render_to_strings(&panel, cx)), cx.read(|cx| render_to_strings(&panel, cx)),
@ -1612,14 +1612,14 @@ mod tests {
format!( format!(
" {}{}", " {}{}",
contact.projects[*project_ix].worktree_root_names.join(", "), contact.projects[*project_ix].worktree_root_names.join(", "),
if project.map_or(true, |project| project.is_public()) { if project.map_or(true, |project| project.is_online()) {
"" ""
} else { } else {
" (becoming private...)" " (becoming private...)"
}, },
) )
} }
ContactEntry::PrivateProject(project) => { ContactEntry::OfflineProject(project) => {
let project = project.upgrade(cx).unwrap().read(cx); let project = project.upgrade(cx).unwrap().read(cx);
format!( format!(
" 🔒 {}{}", " 🔒 {}{}",
@ -1627,7 +1627,7 @@ mod tests {
.worktree_root_names(cx) .worktree_root_names(cx)
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
if project.is_public() { if project.is_online() {
" (becoming public...)" " (becoming public...)"
} else { } else {
"" ""

View file

@ -129,8 +129,8 @@ enum ProjectClientState {
is_shared: bool, is_shared: bool,
remote_id_tx: watch::Sender<Option<u64>>, remote_id_tx: watch::Sender<Option<u64>>,
remote_id_rx: watch::Receiver<Option<u64>>, remote_id_rx: watch::Receiver<Option<u64>>,
public_tx: watch::Sender<bool>, online_tx: watch::Sender<bool>,
public_rx: watch::Receiver<bool>, online_rx: watch::Receiver<bool>,
_maintain_remote_id_task: Task<Option<()>>, _maintain_remote_id_task: Task<Option<()>>,
}, },
Remote { Remote {
@ -315,7 +315,7 @@ impl Project {
} }
pub fn local( pub fn local(
public: bool, online: bool,
client: Arc<Client>, client: Arc<Client>,
user_store: ModelHandle<UserStore>, user_store: ModelHandle<UserStore>,
project_store: ModelHandle<ProjectStore>, project_store: ModelHandle<ProjectStore>,
@ -324,17 +324,17 @@ impl Project {
cx: &mut MutableAppContext, cx: &mut MutableAppContext,
) -> ModelHandle<Self> { ) -> ModelHandle<Self> {
cx.add_model(|cx: &mut ModelContext<Self>| { cx.add_model(|cx: &mut ModelContext<Self>| {
let (public_tx, public_rx) = watch::channel_with(public); let (online_tx, online_rx) = watch::channel_with(online);
let (remote_id_tx, remote_id_rx) = watch::channel(); let (remote_id_tx, remote_id_rx) = watch::channel();
let _maintain_remote_id_task = cx.spawn_weak({ let _maintain_remote_id_task = cx.spawn_weak({
let status_rx = client.clone().status(); let status_rx = client.clone().status();
let public_rx = public_rx.clone(); let online_rx = online_rx.clone();
move |this, mut cx| async move { move |this, mut cx| async move {
let mut stream = Stream::map(status_rx.clone(), drop) let mut stream = Stream::map(status_rx.clone(), drop)
.merge(Stream::map(public_rx.clone(), drop)); .merge(Stream::map(online_rx.clone(), drop));
while stream.recv().await.is_some() { while stream.recv().await.is_some() {
let this = this.upgrade(&cx)?; let this = this.upgrade(&cx)?;
if status_rx.borrow().is_connected() && *public_rx.borrow() { if status_rx.borrow().is_connected() && *online_rx.borrow() {
this.update(&mut cx, |this, cx| this.register(cx)) this.update(&mut cx, |this, cx| this.register(cx))
.await .await
.log_err()?; .log_err()?;
@ -364,8 +364,8 @@ impl Project {
is_shared: false, is_shared: false,
remote_id_tx, remote_id_tx,
remote_id_rx, remote_id_rx,
public_tx, online_tx,
public_rx, online_rx,
_maintain_remote_id_task, _maintain_remote_id_task,
}, },
opened_buffer: (Rc::new(RefCell::new(opened_buffer_tx)), opened_buffer_rx), opened_buffer: (Rc::new(RefCell::new(opened_buffer_tx)), opened_buffer_rx),
@ -558,19 +558,19 @@ impl Project {
} }
let db = self.project_store.read(cx).db.clone(); let db = self.project_store.read(cx).db.clone();
let project_path_keys = self.project_path_keys(cx); let keys = self.db_keys_for_online_state(cx);
let should_be_public = cx.background().spawn(async move { let read_online = cx.background().spawn(async move {
let values = db.read(project_path_keys)?; let values = db.read(keys)?;
anyhow::Ok(values.into_iter().all(|e| e.is_some())) anyhow::Ok(values.into_iter().all(|e| e.is_some()))
}); });
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
let public = should_be_public.await.log_err().unwrap_or(false); let online = read_online.await.log_err().unwrap_or(false);
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
if let ProjectClientState::Local { public_tx, .. } = &mut this.client_state { if let ProjectClientState::Local { online_tx, .. } = &mut this.client_state {
let mut public_tx = public_tx.borrow_mut(); let mut online_tx = online_tx.borrow_mut();
if *public_tx != public { if *online_tx != online {
*public_tx = public; *online_tx = online;
drop(public_tx); drop(online_tx);
this.metadata_changed(false, cx); this.metadata_changed(false, cx);
} }
} }
@ -585,13 +585,13 @@ impl Project {
} }
let db = self.project_store.read(cx).db.clone(); let db = self.project_store.read(cx).db.clone();
let project_path_keys = self.project_path_keys(cx); let keys = self.db_keys_for_online_state(cx);
let public = self.is_public(); let is_online = self.is_online();
cx.background().spawn(async move { cx.background().spawn(async move {
if public { if is_online {
db.write(project_path_keys.into_iter().map(|key| (key, &[]))) db.write(keys.into_iter().map(|key| (key, &[])))
} else { } else {
db.delete(project_path_keys) db.delete(keys)
} }
}) })
} }
@ -675,20 +675,20 @@ impl Project {
&self.fs &self.fs
} }
pub fn set_public(&mut self, is_public: bool, cx: &mut ModelContext<Self>) { pub fn set_online(&mut self, online: bool, cx: &mut ModelContext<Self>) {
if let ProjectClientState::Local { public_tx, .. } = &mut self.client_state { if let ProjectClientState::Local { online_tx, .. } = &mut self.client_state {
let mut public_tx = public_tx.borrow_mut(); let mut online_tx = online_tx.borrow_mut();
if *public_tx != is_public { if *online_tx != online {
*public_tx = is_public; *online_tx = online;
drop(public_tx); drop(online_tx);
self.metadata_changed(true, cx); self.metadata_changed(true, cx);
} }
} }
} }
pub fn is_public(&self) -> bool { pub fn is_online(&self) -> bool {
match &self.client_state { match &self.client_state {
ProjectClientState::Local { public_rx, .. } => *public_rx.borrow(), ProjectClientState::Local { online_rx, .. } => *online_rx.borrow(),
ProjectClientState::Remote { .. } => true, ProjectClientState::Remote { .. } => true,
} }
} }
@ -705,7 +705,7 @@ impl Project {
// Unregistering the project causes the server to send out a // Unregistering the project causes the server to send out a
// contact update removing this project from the host's list // contact update removing this project from the host's list
// of public projects. Wait until this contact update has been // of online projects. Wait until this contact update has been
// processed before clearing out this project's remote id, so // processed before clearing out this project's remote id, so
// that there is no moment where this project appears in the // that there is no moment where this project appears in the
// contact metadata and *also* has no remote id. // contact metadata and *also* has no remote id.
@ -812,11 +812,11 @@ impl Project {
fn metadata_changed(&mut self, persist: bool, cx: &mut ModelContext<Self>) { fn metadata_changed(&mut self, persist: bool, cx: &mut ModelContext<Self>) {
if let ProjectClientState::Local { if let ProjectClientState::Local {
remote_id_rx, remote_id_rx,
public_rx, online_rx,
.. ..
} = &self.client_state } = &self.client_state
{ {
if let (Some(project_id), true) = (*remote_id_rx.borrow(), *public_rx.borrow()) { if let (Some(project_id), true) = (*remote_id_rx.borrow(), *online_rx.borrow()) {
self.client self.client
.send(proto::UpdateProject { .send(proto::UpdateProject {
project_id, project_id,
@ -874,13 +874,13 @@ impl Project {
.map(|tree| tree.read(cx).root_name()) .map(|tree| tree.read(cx).root_name())
} }
fn project_path_keys(&self, cx: &AppContext) -> Vec<String> { fn db_keys_for_online_state(&self, cx: &AppContext) -> Vec<String> {
self.worktrees self.worktrees
.iter() .iter()
.filter_map(|worktree| { .filter_map(|worktree| {
worktree.upgrade(&cx).map(|worktree| { worktree.upgrade(&cx).map(|worktree| {
format!( format!(
"public-project-path:{}", "project-path-online:{}",
worktree worktree
.read(cx) .read(cx)
.as_local() .as_local()

View file

@ -1055,8 +1055,8 @@ impl Workspace {
.clone() .clone()
.unwrap_or_else(|| self.project.clone()); .unwrap_or_else(|| self.project.clone());
project.update(cx, |project, cx| { project.update(cx, |project, cx| {
let public = !project.is_public(); let public = !project.is_online();
project.set_public(public, cx); project.set_online(public, cx);
}); });
} }