Rename project's 'public'/'private' flag to 'online'/'offline'
This commit is contained in:
parent
b2aa831017
commit
e18bc24989
4 changed files with 59 additions and 59 deletions
|
@ -519,7 +519,7 @@ async fn test_private_projects(
|
|||
.read_with(cx_b, |store, _| { store.contacts()[0].projects.is_empty() }));
|
||||
|
||||
// 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();
|
||||
assert!(project_a.read_with(cx_a, |project, _| project.remote_id().is_some()));
|
||||
assert!(!client_b
|
||||
|
|
|
@ -45,7 +45,7 @@ enum ContactEntry {
|
|||
OutgoingRequest(Arc<User>),
|
||||
Contact(Arc<Contact>),
|
||||
ContactProject(Arc<Contact>, usize, Option<WeakModelHandle<Project>>),
|
||||
PrivateProject(WeakModelHandle<Project>),
|
||||
OfflineProject(WeakModelHandle<Project>),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -233,7 +233,7 @@ impl ContactsPanel {
|
|||
cx,
|
||||
)
|
||||
}
|
||||
ContactEntry::PrivateProject(project) => Self::render_private_project(
|
||||
ContactEntry::OfflineProject(project) => Self::render_offline_project(
|
||||
project.clone(),
|
||||
&theme.contacts_panel,
|
||||
&theme.tooltip,
|
||||
|
@ -412,8 +412,8 @@ impl ContactsPanel {
|
|||
.boxed(),
|
||||
)
|
||||
.with_children(open_project.and_then(|open_project| {
|
||||
let is_becoming_private = !open_project.read(cx).is_public();
|
||||
if !mouse_state.hovered && !is_becoming_private {
|
||||
let is_going_offline = !open_project.read(cx).is_online();
|
||||
if !mouse_state.hovered && !is_going_offline {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ impl ContactsPanel {
|
|||
*theme.private_button.style_for(state, false);
|
||||
icon_style.container.background_color =
|
||||
row.container.background_color;
|
||||
if is_becoming_private {
|
||||
if is_going_offline {
|
||||
icon_style.color = theme.disabled_button.color;
|
||||
}
|
||||
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())
|
||||
} else {
|
||||
Some(
|
||||
|
@ -447,7 +447,7 @@ impl ContactsPanel {
|
|||
})
|
||||
.with_tooltip(
|
||||
project_id as usize,
|
||||
"Make project private".to_string(),
|
||||
"Take project offline".to_string(),
|
||||
None,
|
||||
tooltip_style.clone(),
|
||||
cx,
|
||||
|
@ -505,7 +505,7 @@ impl ContactsPanel {
|
|||
.boxed()
|
||||
}
|
||||
|
||||
fn render_private_project(
|
||||
fn render_offline_project(
|
||||
project: WeakModelHandle<Project>,
|
||||
theme: &theme::ContactsPanel,
|
||||
tooltip_style: &TooltipStyle,
|
||||
|
@ -532,7 +532,7 @@ impl ContactsPanel {
|
|||
let row = theme.project_row.style_for(state, is_selected);
|
||||
let mut worktree_root_names = String::new();
|
||||
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) {
|
||||
if !worktree_root_names.is_empty() {
|
||||
worktree_root_names.push_str(", ");
|
||||
|
@ -545,7 +545,7 @@ impl ContactsPanel {
|
|||
let button =
|
||||
MouseEventHandler::new::<TogglePublic, _, _>(project_id, cx, |state, _| {
|
||||
let mut style = *theme.private_button.style_for(state, false);
|
||||
if is_becoming_public {
|
||||
if is_going_online {
|
||||
style.color = theme.disabled_button.color;
|
||||
}
|
||||
render_icon_button(&style, "icons/lock-8.svg")
|
||||
|
@ -555,7 +555,7 @@ impl ContactsPanel {
|
|||
.boxed()
|
||||
});
|
||||
|
||||
if is_becoming_public {
|
||||
if is_going_online {
|
||||
button.boxed()
|
||||
} else {
|
||||
button
|
||||
|
@ -567,7 +567,7 @@ impl ContactsPanel {
|
|||
})
|
||||
.with_tooltip(
|
||||
project_id,
|
||||
"Make project public".to_string(),
|
||||
"Take project online".to_string(),
|
||||
None,
|
||||
tooltip_style.clone(),
|
||||
cx,
|
||||
|
@ -864,7 +864,7 @@ impl ContactsPanel {
|
|||
if project.read(cx).visible_worktrees(cx).next().is_none() {
|
||||
None
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
ContactEntry::PrivateProject(project_1) => {
|
||||
if let ContactEntry::PrivateProject(project_2) = other {
|
||||
ContactEntry::OfflineProject(project_1) => {
|
||||
if let ContactEntry::OfflineProject(project_2) = other {
|
||||
return project_1.id() == project_2.id();
|
||||
}
|
||||
}
|
||||
|
@ -1351,7 +1351,7 @@ mod tests {
|
|||
|
||||
// Make a project public. It appears as loading, since the project
|
||||
// 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();
|
||||
assert_eq!(
|
||||
cx.read(|cx| render_to_strings(&panel, cx)),
|
||||
|
@ -1458,7 +1458,7 @@ mod tests {
|
|||
);
|
||||
|
||||
// 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();
|
||||
assert_eq!(
|
||||
cx.read(|cx| render_to_strings(&panel, cx)),
|
||||
|
@ -1612,14 +1612,14 @@ mod tests {
|
|||
format!(
|
||||
" {}{}",
|
||||
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 {
|
||||
" (becoming private...)"
|
||||
},
|
||||
)
|
||||
}
|
||||
ContactEntry::PrivateProject(project) => {
|
||||
ContactEntry::OfflineProject(project) => {
|
||||
let project = project.upgrade(cx).unwrap().read(cx);
|
||||
format!(
|
||||
" 🔒 {}{}",
|
||||
|
@ -1627,7 +1627,7 @@ mod tests {
|
|||
.worktree_root_names(cx)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
if project.is_public() {
|
||||
if project.is_online() {
|
||||
" (becoming public...)"
|
||||
} else {
|
||||
""
|
||||
|
|
|
@ -129,8 +129,8 @@ enum ProjectClientState {
|
|||
is_shared: bool,
|
||||
remote_id_tx: watch::Sender<Option<u64>>,
|
||||
remote_id_rx: watch::Receiver<Option<u64>>,
|
||||
public_tx: watch::Sender<bool>,
|
||||
public_rx: watch::Receiver<bool>,
|
||||
online_tx: watch::Sender<bool>,
|
||||
online_rx: watch::Receiver<bool>,
|
||||
_maintain_remote_id_task: Task<Option<()>>,
|
||||
},
|
||||
Remote {
|
||||
|
@ -315,7 +315,7 @@ impl Project {
|
|||
}
|
||||
|
||||
pub fn local(
|
||||
public: bool,
|
||||
online: bool,
|
||||
client: Arc<Client>,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
project_store: ModelHandle<ProjectStore>,
|
||||
|
@ -324,17 +324,17 @@ impl Project {
|
|||
cx: &mut MutableAppContext,
|
||||
) -> ModelHandle<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 _maintain_remote_id_task = cx.spawn_weak({
|
||||
let status_rx = client.clone().status();
|
||||
let public_rx = public_rx.clone();
|
||||
let online_rx = online_rx.clone();
|
||||
move |this, mut cx| async move {
|
||||
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() {
|
||||
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))
|
||||
.await
|
||||
.log_err()?;
|
||||
|
@ -364,8 +364,8 @@ impl Project {
|
|||
is_shared: false,
|
||||
remote_id_tx,
|
||||
remote_id_rx,
|
||||
public_tx,
|
||||
public_rx,
|
||||
online_tx,
|
||||
online_rx,
|
||||
_maintain_remote_id_task,
|
||||
},
|
||||
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 project_path_keys = self.project_path_keys(cx);
|
||||
let should_be_public = cx.background().spawn(async move {
|
||||
let values = db.read(project_path_keys)?;
|
||||
let keys = self.db_keys_for_online_state(cx);
|
||||
let read_online = cx.background().spawn(async move {
|
||||
let values = db.read(keys)?;
|
||||
anyhow::Ok(values.into_iter().all(|e| e.is_some()))
|
||||
});
|
||||
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| {
|
||||
if let ProjectClientState::Local { public_tx, .. } = &mut this.client_state {
|
||||
let mut public_tx = public_tx.borrow_mut();
|
||||
if *public_tx != public {
|
||||
*public_tx = public;
|
||||
drop(public_tx);
|
||||
if let ProjectClientState::Local { online_tx, .. } = &mut this.client_state {
|
||||
let mut online_tx = online_tx.borrow_mut();
|
||||
if *online_tx != online {
|
||||
*online_tx = online;
|
||||
drop(online_tx);
|
||||
this.metadata_changed(false, cx);
|
||||
}
|
||||
}
|
||||
|
@ -585,13 +585,13 @@ impl Project {
|
|||
}
|
||||
|
||||
let db = self.project_store.read(cx).db.clone();
|
||||
let project_path_keys = self.project_path_keys(cx);
|
||||
let public = self.is_public();
|
||||
let keys = self.db_keys_for_online_state(cx);
|
||||
let is_online = self.is_online();
|
||||
cx.background().spawn(async move {
|
||||
if public {
|
||||
db.write(project_path_keys.into_iter().map(|key| (key, &[])))
|
||||
if is_online {
|
||||
db.write(keys.into_iter().map(|key| (key, &[])))
|
||||
} else {
|
||||
db.delete(project_path_keys)
|
||||
db.delete(keys)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -675,20 +675,20 @@ impl Project {
|
|||
&self.fs
|
||||
}
|
||||
|
||||
pub fn set_public(&mut self, is_public: bool, cx: &mut ModelContext<Self>) {
|
||||
if let ProjectClientState::Local { public_tx, .. } = &mut self.client_state {
|
||||
let mut public_tx = public_tx.borrow_mut();
|
||||
if *public_tx != is_public {
|
||||
*public_tx = is_public;
|
||||
drop(public_tx);
|
||||
pub fn set_online(&mut self, online: bool, cx: &mut ModelContext<Self>) {
|
||||
if let ProjectClientState::Local { online_tx, .. } = &mut self.client_state {
|
||||
let mut online_tx = online_tx.borrow_mut();
|
||||
if *online_tx != online {
|
||||
*online_tx = online;
|
||||
drop(online_tx);
|
||||
self.metadata_changed(true, cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_public(&self) -> bool {
|
||||
pub fn is_online(&self) -> bool {
|
||||
match &self.client_state {
|
||||
ProjectClientState::Local { public_rx, .. } => *public_rx.borrow(),
|
||||
ProjectClientState::Local { online_rx, .. } => *online_rx.borrow(),
|
||||
ProjectClientState::Remote { .. } => true,
|
||||
}
|
||||
}
|
||||
|
@ -705,7 +705,7 @@ impl Project {
|
|||
|
||||
// Unregistering the project causes the server to send out a
|
||||
// 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
|
||||
// that there is no moment where this project appears in the
|
||||
// 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>) {
|
||||
if let ProjectClientState::Local {
|
||||
remote_id_rx,
|
||||
public_rx,
|
||||
online_rx,
|
||||
..
|
||||
} = &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
|
||||
.send(proto::UpdateProject {
|
||||
project_id,
|
||||
|
@ -874,13 +874,13 @@ impl Project {
|
|||
.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
|
||||
.iter()
|
||||
.filter_map(|worktree| {
|
||||
worktree.upgrade(&cx).map(|worktree| {
|
||||
format!(
|
||||
"public-project-path:{}",
|
||||
"project-path-online:{}",
|
||||
worktree
|
||||
.read(cx)
|
||||
.as_local()
|
||||
|
|
|
@ -1055,8 +1055,8 @@ impl Workspace {
|
|||
.clone()
|
||||
.unwrap_or_else(|| self.project.clone());
|
||||
project.update(cx, |project, cx| {
|
||||
let public = !project.is_public();
|
||||
project.set_public(public, cx);
|
||||
let public = !project.is_online();
|
||||
project.set_online(public, cx);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue