Rename Collaborators to Contacts

This will allow us to use the word "collaborator" to describe users that are actively collaborating on a worktree.

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Nathan Sobo 2021-11-26 10:59:41 -07:00
parent 9f29eeda03
commit cd2c3c3606
6 changed files with 113 additions and 125 deletions

View file

@ -118,8 +118,8 @@ impl Server {
let (connection_id, handle_io, mut incoming_rx) =
this.peer.add_connection(connection).await;
this.state_mut().add_connection(connection_id, user_id);
if let Err(err) = this.update_collaborators_for_users(&[user_id]).await {
log::error!("error updating collaborators for {:?}: {}", user_id, err);
if let Err(err) = this.update_contacts_for_users(&[user_id]).await {
log::error!("error updating contacts for {:?}: {}", user_id, err);
}
let handle_io = handle_io.fuse();
@ -196,7 +196,7 @@ impl Server {
.await?;
}
self.update_collaborators_for_users(removed_connection.collaborator_ids.iter())
self.update_contacts_for_users(removed_connection.contact_ids.iter())
.await?;
Ok(())
@ -214,12 +214,12 @@ impl Server {
let receipt = request.receipt();
let host_user_id = self.state().user_id_for_connection(request.sender_id)?;
let mut collaborator_user_ids = HashSet::new();
collaborator_user_ids.insert(host_user_id);
let mut contact_user_ids = HashSet::new();
contact_user_ids.insert(host_user_id);
for github_login in request.payload.collaborator_logins {
match self.app_state.db.create_user(&github_login, false).await {
Ok(collaborator_user_id) => {
collaborator_user_ids.insert(collaborator_user_id);
Ok(contact_user_id) => {
contact_user_ids.insert(contact_user_id);
}
Err(err) => {
let message = err.to_string();
@ -231,11 +231,11 @@ impl Server {
}
}
let collaborator_user_ids = collaborator_user_ids.into_iter().collect::<Vec<_>>();
let contact_user_ids = contact_user_ids.into_iter().collect::<Vec<_>>();
let worktree_id = self.state_mut().add_worktree(Worktree {
host_connection_id: request.sender_id,
host_user_id,
collaborator_user_ids: collaborator_user_ids.clone(),
contact_user_ids: contact_user_ids.clone(),
root_name: request.payload.root_name,
share: None,
});
@ -243,8 +243,7 @@ impl Server {
self.peer
.respond(receipt, proto::OpenWorktreeResponse { worktree_id })
.await?;
self.update_collaborators_for_users(&collaborator_user_ids)
.await?;
self.update_contacts_for_users(&contact_user_ids).await?;
Ok(())
}
@ -269,7 +268,7 @@ impl Server {
)
.await?;
}
self.update_collaborators_for_users(&worktree.collaborator_user_ids)
self.update_contacts_for_users(&worktree.contact_user_ids)
.await?;
Ok(())
}
@ -288,15 +287,14 @@ impl Server {
.map(|entry| (entry.id, entry))
.collect();
let collaborator_user_ids =
let contact_user_ids =
self.state_mut()
.share_worktree(worktree.id, request.sender_id, entries);
if let Some(collaborator_user_ids) = collaborator_user_ids {
if let Some(contact_user_ids) = contact_user_ids {
self.peer
.respond(request.receipt(), proto::ShareWorktreeResponse {})
.await?;
self.update_collaborators_for_users(&collaborator_user_ids)
.await?;
self.update_contacts_for_users(&contact_user_ids).await?;
} else {
self.peer
.respond_with_error(
@ -324,7 +322,7 @@ impl Server {
.send(conn_id, proto::UnshareWorktree { worktree_id })
})
.await?;
self.update_collaborators_for_users(&worktree.collaborator_ids)
self.update_contacts_for_users(&worktree.contact_ids)
.await?;
Ok(())
@ -368,12 +366,12 @@ impl Server {
peers,
};
let connection_ids = joined.worktree.connection_ids();
let collaborator_user_ids = joined.worktree.collaborator_user_ids.clone();
Ok((response, connection_ids, collaborator_user_ids))
let contact_user_ids = joined.worktree.contact_user_ids.clone();
Ok((response, connection_ids, contact_user_ids))
});
match response_data {
Ok((response, connection_ids, collaborator_user_ids)) => {
Ok((response, connection_ids, contact_user_ids)) => {
broadcast(request.sender_id, connection_ids, |conn_id| {
self.peer.send(
conn_id,
@ -389,8 +387,7 @@ impl Server {
})
.await?;
self.peer.respond(request.receipt(), response).await?;
self.update_collaborators_for_users(&collaborator_user_ids)
.await?;
self.update_contacts_for_users(&contact_user_ids).await?;
}
Err(error) => {
self.peer
@ -425,7 +422,7 @@ impl Server {
)
})
.await?;
self.update_collaborators_for_users(&worktree.collaborator_ids)
self.update_contacts_for_users(&worktree.contact_ids)
.await?;
}
Ok(())
@ -595,7 +592,7 @@ impl Server {
Ok(())
}
async fn update_collaborators_for_users<'a>(
async fn update_contacts_for_users<'a>(
self: &Arc<Server>,
user_ids: impl IntoIterator<Item = &'a UserId>,
) -> tide::Result<()> {
@ -604,12 +601,12 @@ impl Server {
{
let state = self.state();
for user_id in user_ids {
let collaborators = state.collaborators_for_user(*user_id);
let contacts = state.contacts_for_user(*user_id);
for connection_id in state.connection_ids_for_user(*user_id) {
send_futures.push(self.peer.send(
connection_id,
proto::UpdateCollaborators {
collaborators: collaborators.clone(),
proto::UpdateContacts {
contacts: contacts.clone(),
},
));
}
@ -2108,7 +2105,7 @@ mod tests {
}
#[gpui::test]
async fn test_collaborators(
async fn test_contacts(
mut cx_a: TestAppContext,
mut cx_b: TestAppContext,
mut cx_c: TestAppContext,
@ -2145,17 +2142,17 @@ mod tests {
user_store_a
.condition(&cx_a, |user_store, _| {
collaborators(user_store) == vec![("user_a", vec![("a", vec![])])]
contacts(user_store) == vec![("user_a", vec![("a", vec![])])]
})
.await;
user_store_b
.condition(&cx_b, |user_store, _| {
collaborators(user_store) == vec![("user_a", vec![("a", vec![])])]
contacts(user_store) == vec![("user_a", vec![("a", vec![])])]
})
.await;
user_store_c
.condition(&cx_c, |user_store, _| {
collaborators(user_store) == vec![("user_a", vec![("a", vec![])])]
contacts(user_store) == vec![("user_a", vec![("a", vec![])])]
})
.await;
@ -2175,37 +2172,37 @@ mod tests {
user_store_a
.condition(&cx_a, |user_store, _| {
collaborators(user_store) == vec![("user_a", vec![("a", vec!["user_b"])])]
contacts(user_store) == vec![("user_a", vec![("a", vec!["user_b"])])]
})
.await;
user_store_b
.condition(&cx_b, |user_store, _| {
collaborators(user_store) == vec![("user_a", vec![("a", vec!["user_b"])])]
contacts(user_store) == vec![("user_a", vec![("a", vec!["user_b"])])]
})
.await;
user_store_c
.condition(&cx_c, |user_store, _| {
collaborators(user_store) == vec![("user_a", vec![("a", vec!["user_b"])])]
contacts(user_store) == vec![("user_a", vec![("a", vec!["user_b"])])]
})
.await;
cx_a.update(move |_| drop(worktree_a));
user_store_a
.condition(&cx_a, |user_store, _| collaborators(user_store) == vec![])
.condition(&cx_a, |user_store, _| contacts(user_store) == vec![])
.await;
user_store_b
.condition(&cx_b, |user_store, _| collaborators(user_store) == vec![])
.condition(&cx_b, |user_store, _| contacts(user_store) == vec![])
.await;
user_store_c
.condition(&cx_c, |user_store, _| collaborators(user_store) == vec![])
.condition(&cx_c, |user_store, _| contacts(user_store) == vec![])
.await;
fn collaborators(user_store: &UserStore) -> Vec<(&str, Vec<(&str, Vec<&str>)>)> {
fn contacts(user_store: &UserStore) -> Vec<(&str, Vec<(&str, Vec<&str>)>)> {
user_store
.collaborators()
.contacts()
.iter()
.map(|collaborator| {
let worktrees = collaborator
.map(|contact| {
let worktrees = contact
.worktrees
.iter()
.map(|w| {
@ -2215,7 +2212,7 @@ mod tests {
)
})
.collect();
(collaborator.user.github_login.as_str(), worktrees)
(contact.user.github_login.as_str(), worktrees)
})
.collect()
}

View file

@ -22,7 +22,7 @@ struct ConnectionState {
pub struct Worktree {
pub host_connection_id: ConnectionId,
pub host_user_id: UserId,
pub collaborator_user_ids: Vec<UserId>,
pub contact_user_ids: Vec<UserId>,
pub root_name: String,
pub share: Option<WorktreeShare>,
}
@ -44,7 +44,7 @@ pub type ReplicaId = u16;
pub struct RemovedConnectionState {
pub hosted_worktrees: HashMap<u64, Worktree>,
pub guest_worktree_ids: HashMap<u64, Vec<ConnectionId>>,
pub collaborator_ids: HashSet<UserId>,
pub contact_ids: HashSet<UserId>,
}
pub struct JoinedWorktree<'a> {
@ -54,12 +54,12 @@ pub struct JoinedWorktree<'a> {
pub struct UnsharedWorktree {
pub connection_ids: Vec<ConnectionId>,
pub collaborator_ids: Vec<UserId>,
pub contact_ids: Vec<UserId>,
}
pub struct LeftWorktree {
pub connection_ids: Vec<ConnectionId>,
pub collaborator_ids: Vec<UserId>,
pub contact_ids: Vec<UserId>,
}
impl Store {
@ -107,14 +107,14 @@ impl Store {
for worktree_id in connection.worktrees.clone() {
if let Ok(worktree) = self.remove_worktree(worktree_id, connection_id) {
result
.collaborator_ids
.extend(worktree.collaborator_user_ids.iter().copied());
.contact_ids
.extend(worktree.contact_user_ids.iter().copied());
result.hosted_worktrees.insert(worktree_id, worktree);
} else if let Some(worktree) = self.leave_worktree(connection_id, worktree_id) {
result
.guest_worktree_ids
.insert(worktree_id, worktree.connection_ids);
result.collaborator_ids.extend(worktree.collaborator_ids);
result.contact_ids.extend(worktree.contact_ids);
}
}
@ -171,8 +171,8 @@ impl Store {
.copied()
}
pub fn collaborators_for_user(&self, user_id: UserId) -> Vec<proto::Collaborator> {
let mut collaborators = HashMap::new();
pub fn contacts_for_user(&self, user_id: UserId) -> Vec<proto::Contact> {
let mut contacts = HashMap::new();
for worktree_id in self
.visible_worktrees_by_user_id
.get(&user_id)
@ -190,9 +190,9 @@ impl Store {
}
if let Ok(host_user_id) = self.user_id_for_connection(worktree.host_connection_id) {
collaborators
contacts
.entry(host_user_id)
.or_insert_with(|| proto::Collaborator {
.or_insert_with(|| proto::Contact {
user_id: host_user_id.to_proto(),
worktrees: Vec::new(),
})
@ -206,14 +206,14 @@ impl Store {
}
}
collaborators.into_values().collect()
contacts.into_values().collect()
}
pub fn add_worktree(&mut self, worktree: Worktree) -> u64 {
let worktree_id = self.next_worktree_id;
for collaborator_user_id in &worktree.collaborator_user_ids {
for contact_user_id in &worktree.contact_user_ids {
self.visible_worktrees_by_user_id
.entry(*collaborator_user_id)
.entry(*contact_user_id)
.or_default()
.insert(worktree_id);
}
@ -255,10 +255,9 @@ impl Store {
}
}
for collaborator_user_id in &worktree.collaborator_user_ids {
if let Some(visible_worktrees) = self
.visible_worktrees_by_user_id
.get_mut(&collaborator_user_id)
for contact_user_id in &worktree.contact_user_ids {
if let Some(visible_worktrees) =
self.visible_worktrees_by_user_id.get_mut(&contact_user_id)
{
visible_worktrees.remove(&worktree_id);
}
@ -283,7 +282,7 @@ impl Store {
active_replica_ids: Default::default(),
entries,
});
return Some(worktree.collaborator_user_ids.clone());
return Some(worktree.contact_user_ids.clone());
}
}
None
@ -305,7 +304,7 @@ impl Store {
}
let connection_ids = worktree.connection_ids();
let collaborator_ids = worktree.collaborator_user_ids.clone();
let contact_ids = worktree.contact_user_ids.clone();
if let Some(share) = worktree.share.take() {
for connection_id in share.guests.into_keys() {
if let Some(connection) = self.connections.get_mut(&connection_id) {
@ -318,7 +317,7 @@ impl Store {
Ok(UnsharedWorktree {
connection_ids,
collaborator_ids,
contact_ids,
})
} else {
Err(anyhow!("worktree is not shared"))?
@ -339,7 +338,7 @@ impl Store {
.worktrees
.get_mut(&worktree_id)
.and_then(|worktree| {
if worktree.collaborator_user_ids.contains(&user_id) {
if worktree.contact_user_ids.contains(&user_id) {
Some(worktree)
} else {
None
@ -381,14 +380,14 @@ impl Store {
}
let connection_ids = worktree.connection_ids();
let collaborator_ids = worktree.collaborator_user_ids.clone();
let contact_ids = worktree.contact_user_ids.clone();
#[cfg(test)]
self.check_invariants();
Some(LeftWorktree {
connection_ids,
collaborator_ids,
contact_ids,
})
}
@ -530,11 +529,9 @@ impl Store {
let host_connection = self.connections.get(&worktree.host_connection_id).unwrap();
assert!(host_connection.worktrees.contains(worktree_id));
for collaborator_id in &worktree.collaborator_user_ids {
let visible_worktree_ids = self
.visible_worktrees_by_user_id
.get(collaborator_id)
.unwrap();
for contact_id in &worktree.contact_user_ids {
let visible_worktree_ids =
self.visible_worktrees_by_user_id.get(contact_id).unwrap();
assert!(visible_worktree_ids.contains(worktree_id));
}
@ -558,7 +555,7 @@ impl Store {
for (user_id, visible_worktree_ids) in &self.visible_worktrees_by_user_id {
for worktree_id in visible_worktree_ids {
let worktree = self.worktrees.get(worktree_id).unwrap();
assert!(worktree.collaborator_user_ids.contains(user_id));
assert!(worktree.contact_user_ids.contains(user_id));
}
}