From 1996b01a7464cc9d4e12d73b6eae1ab5a54fb309 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 13 May 2022 14:57:55 -0700 Subject: [PATCH] Tell host to unshare project when last guest leaves --- crates/collab/src/rpc.rs | 7 +++++++ crates/collab/src/rpc/store.rs | 2 ++ 2 files changed, 9 insertions(+) diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rs index c5141f16b3..fe8335c5fe 100644 --- a/crates/collab/src/rpc.rs +++ b/crates/collab/src/rpc.rs @@ -634,6 +634,7 @@ impl Server { { let mut state = self.store_mut().await; project = state.leave_project(sender_id, project_id)?; + let unshare = project.connection_ids.len() <= 1; broadcast(sender_id, project.connection_ids, |conn_id| { self.peer.send( conn_id, @@ -643,6 +644,12 @@ impl Server { }, ) }); + if unshare { + self.peer.send( + project.host_connection_id, + proto::ProjectUnshared { project_id }, + )?; + } } self.update_user_contacts(project.host_user_id).await?; Ok(()) diff --git a/crates/collab/src/rpc/store.rs b/crates/collab/src/rpc/store.rs index 4d32ead37d..81e4c9633b 100644 --- a/crates/collab/src/rpc/store.rs +++ b/crates/collab/src/rpc/store.rs @@ -58,6 +58,7 @@ pub struct RemovedConnectionState { pub struct LeftProject { pub connection_ids: Vec, pub host_user_id: UserId, + pub host_connection_id: ConnectionId, } #[derive(Copy, Clone)] @@ -504,6 +505,7 @@ impl Store { Ok(LeftProject { connection_ids: project.connection_ids(), + host_connection_id: project.host_connection_id, host_user_id: project.host_user_id, }) }