From 15f666a50acc5cab4ac8468d3991cbc021458c51 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 20 Dec 2022 18:03:33 -0800 Subject: [PATCH] Refresh project collaborator connection id for rejoined projects --- crates/collab/src/db.rs | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rs index 7ef7edd8cc5d257182697194c9d394e2a827106e..8b275bb680ec558790b39619d02fd6a3f961c367 100644 --- a/crates/collab/src/db.rs +++ b/crates/collab/src/db.rs @@ -1428,10 +1428,8 @@ impl Database { for rejoined_project in &rejoin_room.rejoined_projects { let project_id = ProjectId::from_proto(rejoined_project.id); let Some(project) = project::Entity::find_by_id(project_id) - .one(&*tx) - .await? else { - continue - }; + .one(&*tx) + .await? else { continue }; let mut worktrees = Vec::new(); let db_worktrees = project.find_related(worktree::Entity).all(&*tx).await?; @@ -1504,7 +1502,25 @@ impl Database { let mut collaborators = project .find_related(project_collaborator::Entity) .all(&*tx) - .await? + .await?; + let self_collaborator = if let Some(self_collaborator_ix) = collaborators + .iter() + .position(|collaborator| collaborator.user_id == user_id) + { + collaborators.swap_remove(self_collaborator_ix) + } else { + continue; + }; + let old_connection_id = self_collaborator.connection(); + project_collaborator::Entity::update(project_collaborator::ActiveModel { + connection_id: ActiveValue::set(connection.id as i32), + connection_server_id: ActiveValue::set(ServerId(connection.owner_id as i32)), + ..self_collaborator.into_active_model() + }) + .exec(&*tx) + .await?; + + let collaborators = collaborators .into_iter() .map(|collaborator| ProjectCollaborator { connection_id: collaborator.connection(), @@ -1514,16 +1530,6 @@ impl Database { }) .collect::>(); - let old_connection_id = if let Some(self_collaborator_ix) = collaborators - .iter() - .position(|collaborator| collaborator.user_id == user_id) - { - let self_collaborator = collaborators.swap_remove(self_collaborator_ix); - self_collaborator.connection_id - } else { - continue; - }; - rejoined_projects.push(RejoinedProject { id: project_id, old_connection_id,