Simplify Collaborator
to stop including the user
It can be retrieved from the `Room` and we're guaranteed to have a room in order to have collaborators in a project.
This commit is contained in:
parent
debedaf004
commit
41240351d3
3 changed files with 11 additions and 35 deletions
|
@ -318,24 +318,12 @@ async fn test_share_project(
|
||||||
// Join that project as client B
|
// Join that project as client B
|
||||||
let client_b_peer_id = client_b.peer_id;
|
let client_b_peer_id = client_b.peer_id;
|
||||||
let project_b = client_b.build_remote_project(project_id, cx_b).await;
|
let project_b = client_b.build_remote_project(project_id, cx_b).await;
|
||||||
let replica_id_b = project_b.read_with(cx_b, |project, _| {
|
let replica_id_b = project_b.read_with(cx_b, |project, _| project.replica_id());
|
||||||
assert_eq!(
|
|
||||||
project
|
|
||||||
.collaborators()
|
|
||||||
.get(&client_a.peer_id)
|
|
||||||
.unwrap()
|
|
||||||
.user
|
|
||||||
.github_login,
|
|
||||||
"user_a"
|
|
||||||
);
|
|
||||||
project.replica_id()
|
|
||||||
});
|
|
||||||
|
|
||||||
deterministic.run_until_parked();
|
deterministic.run_until_parked();
|
||||||
project_a.read_with(cx_a, |project, _| {
|
project_a.read_with(cx_a, |project, _| {
|
||||||
let client_b_collaborator = project.collaborators().get(&client_b_peer_id).unwrap();
|
let client_b_collaborator = project.collaborators().get(&client_b_peer_id).unwrap();
|
||||||
assert_eq!(client_b_collaborator.replica_id, replica_id_b);
|
assert_eq!(client_b_collaborator.replica_id, replica_id_b);
|
||||||
assert_eq!(client_b_collaborator.user.github_login, "user_b");
|
|
||||||
});
|
});
|
||||||
project_b.read_with(cx_b, |project, cx| {
|
project_b.read_with(cx_b, |project, cx| {
|
||||||
let worktree = project.worktrees(cx).next().unwrap().read(cx);
|
let worktree = project.worktrees(cx).next().unwrap().read(cx);
|
||||||
|
|
|
@ -223,13 +223,14 @@ impl CollabTitlebarItem {
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.remote_participants()
|
.remote_participants()
|
||||||
.get(&collaborator.peer_id)?;
|
.get(&collaborator.peer_id)?;
|
||||||
|
let user = participant.user.clone();
|
||||||
let is_active = project_id.map_or(false, |project_id| {
|
let is_active = project_id.map_or(false, |project_id| {
|
||||||
participant.location == ParticipantLocation::Project { project_id }
|
participant.location == ParticipantLocation::Project { project_id }
|
||||||
});
|
});
|
||||||
Some(self.render_avatar(
|
Some(self.render_avatar(
|
||||||
collaborator.user.avatar.clone()?,
|
user.avatar.clone()?,
|
||||||
collaborator.replica_id,
|
collaborator.replica_id,
|
||||||
Some((collaborator.peer_id, &collaborator.user.github_login)),
|
Some((collaborator.peer_id, &user.github_login)),
|
||||||
is_active,
|
is_active,
|
||||||
workspace,
|
workspace,
|
||||||
theme,
|
theme,
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub mod worktree;
|
||||||
mod project_tests;
|
mod project_tests;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use client::{proto, Client, PeerId, TypedEnvelope, User, UserStore};
|
use client::{proto, Client, PeerId, TypedEnvelope, UserStore};
|
||||||
use clock::ReplicaId;
|
use clock::ReplicaId;
|
||||||
use collections::{hash_map, BTreeMap, HashMap, HashSet};
|
use collections::{hash_map, BTreeMap, HashMap, HashSet};
|
||||||
use futures::{future::Shared, AsyncWriteExt, Future, FutureExt, StreamExt, TryFutureExt};
|
use futures::{future::Shared, AsyncWriteExt, Future, FutureExt, StreamExt, TryFutureExt};
|
||||||
|
@ -165,7 +165,6 @@ enum ProjectClientState {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Collaborator {
|
pub struct Collaborator {
|
||||||
pub user: Arc<User>,
|
|
||||||
pub peer_id: PeerId,
|
pub peer_id: PeerId,
|
||||||
pub replica_id: ReplicaId,
|
pub replica_id: ReplicaId,
|
||||||
}
|
}
|
||||||
|
@ -582,7 +581,7 @@ impl Project {
|
||||||
.await?;
|
.await?;
|
||||||
let mut collaborators = HashMap::default();
|
let mut collaborators = HashMap::default();
|
||||||
for message in response.collaborators {
|
for message in response.collaborators {
|
||||||
let collaborator = Collaborator::from_proto(message, &user_store, &mut cx).await?;
|
let collaborator = Collaborator::from_proto(message);
|
||||||
collaborators.insert(collaborator.peer_id, collaborator);
|
collaborators.insert(collaborator.peer_id, collaborator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4451,14 +4450,13 @@ impl Project {
|
||||||
_: Arc<Client>,
|
_: Arc<Client>,
|
||||||
mut cx: AsyncAppContext,
|
mut cx: AsyncAppContext,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let user_store = this.read_with(&cx, |this, _| this.user_store.clone());
|
|
||||||
let collaborator = envelope
|
let collaborator = envelope
|
||||||
.payload
|
.payload
|
||||||
.collaborator
|
.collaborator
|
||||||
.take()
|
.take()
|
||||||
.ok_or_else(|| anyhow!("empty collaborator"))?;
|
.ok_or_else(|| anyhow!("empty collaborator"))?;
|
||||||
|
|
||||||
let collaborator = Collaborator::from_proto(collaborator, &user_store, &mut cx).await?;
|
let collaborator = Collaborator::from_proto(collaborator);
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
this.collaborators
|
this.collaborators
|
||||||
.insert(collaborator.peer_id, collaborator);
|
.insert(collaborator.peer_id, collaborator);
|
||||||
|
@ -5904,21 +5902,10 @@ impl Entity for Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Collaborator {
|
impl Collaborator {
|
||||||
fn from_proto(
|
fn from_proto(message: proto::Collaborator) -> Self {
|
||||||
message: proto::Collaborator,
|
Self {
|
||||||
user_store: &ModelHandle<UserStore>,
|
peer_id: PeerId(message.peer_id),
|
||||||
cx: &mut AsyncAppContext,
|
replica_id: message.replica_id as ReplicaId,
|
||||||
) -> impl Future<Output = Result<Self>> {
|
|
||||||
let user = user_store.update(cx, |user_store, cx| {
|
|
||||||
user_store.get_user(message.user_id, cx)
|
|
||||||
});
|
|
||||||
|
|
||||||
async move {
|
|
||||||
Ok(Self {
|
|
||||||
peer_id: PeerId(message.peer_id),
|
|
||||||
user: user.await?,
|
|
||||||
replica_id: message.replica_id as ReplicaId,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue