Simplify `Collaborator` to stop including the user

Antonio Scandurra created

It can be retrieved from the `Room` and we're guaranteed to have
a room in order to have collaborators in a project.

Change summary

crates/collab/src/integration_tests.rs       | 14 ----------
crates/collab_ui/src/collab_titlebar_item.rs |  5 ++-
crates/project/src/project.rs                | 27 +++++----------------
3 files changed, 11 insertions(+), 35 deletions(-)

Detailed changes

crates/collab/src/integration_tests.rs 🔗

@@ -318,24 +318,12 @@ async fn test_share_project(
     // Join that project as client B
     let client_b_peer_id = client_b.peer_id;
     let project_b = client_b.build_remote_project(project_id, cx_b).await;
-    let replica_id_b = project_b.read_with(cx_b, |project, _| {
-        assert_eq!(
-            project
-                .collaborators()
-                .get(&client_a.peer_id)
-                .unwrap()
-                .user
-                .github_login,
-            "user_a"
-        );
-        project.replica_id()
-    });
+    let replica_id_b = project_b.read_with(cx_b, |project, _| project.replica_id());
 
     deterministic.run_until_parked();
     project_a.read_with(cx_a, |project, _| {
         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.user.github_login, "user_b");
     });
     project_b.read_with(cx_b, |project, cx| {
         let worktree = project.worktrees(cx).next().unwrap().read(cx);

crates/collab_ui/src/collab_titlebar_item.rs 🔗

@@ -223,13 +223,14 @@ impl CollabTitlebarItem {
                         .read(cx)
                         .remote_participants()
                         .get(&collaborator.peer_id)?;
+                    let user = participant.user.clone();
                     let is_active = project_id.map_or(false, |project_id| {
                         participant.location == ParticipantLocation::Project { project_id }
                     });
                     Some(self.render_avatar(
-                        collaborator.user.avatar.clone()?,
+                        user.avatar.clone()?,
                         collaborator.replica_id,
-                        Some((collaborator.peer_id, &collaborator.user.github_login)),
+                        Some((collaborator.peer_id, &user.github_login)),
                         is_active,
                         workspace,
                         theme,

crates/project/src/project.rs 🔗

@@ -9,7 +9,7 @@ pub mod worktree;
 mod project_tests;
 
 use anyhow::{anyhow, Context, Result};
-use client::{proto, Client, PeerId, TypedEnvelope, User, UserStore};
+use client::{proto, Client, PeerId, TypedEnvelope, UserStore};
 use clock::ReplicaId;
 use collections::{hash_map, BTreeMap, HashMap, HashSet};
 use futures::{future::Shared, AsyncWriteExt, Future, FutureExt, StreamExt, TryFutureExt};
@@ -165,7 +165,6 @@ enum ProjectClientState {
 
 #[derive(Clone, Debug)]
 pub struct Collaborator {
-    pub user: Arc<User>,
     pub peer_id: PeerId,
     pub replica_id: ReplicaId,
 }
@@ -582,7 +581,7 @@ impl Project {
             .await?;
         let mut collaborators = HashMap::default();
         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);
         }
 
@@ -4451,14 +4450,13 @@ impl Project {
         _: Arc<Client>,
         mut cx: AsyncAppContext,
     ) -> Result<()> {
-        let user_store = this.read_with(&cx, |this, _| this.user_store.clone());
         let collaborator = envelope
             .payload
             .collaborator
             .take()
             .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.collaborators
                 .insert(collaborator.peer_id, collaborator);
@@ -5904,21 +5902,10 @@ impl Entity for Project {
 }
 
 impl Collaborator {
-    fn from_proto(
-        message: proto::Collaborator,
-        user_store: &ModelHandle<UserStore>,
-        cx: &mut AsyncAppContext,
-    ) -> 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,
-            })
+    fn from_proto(message: proto::Collaborator) -> Self {
+        Self {
+            peer_id: PeerId(message.peer_id),
+            replica_id: message.replica_id as ReplicaId,
         }
     }
 }