Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
WIP
Antonio Scandurra2145965749b0
diff --git a/crates/collab/migrations.sqlite/20221109000000_test_schema.sql b/crates/collab/migrations.sqlite/20221109000000_test_schema.sqlindex 44495f16ce3..477cc5d6075 100644--- a/crates/collab/migrations.sqlite/20221109000000_test_schema.sql+++ b/crates/collab/migrations.sqlite/20221109000000_test_schema.sql@@ -68,10 +68,11 @@ CREATE TABLE "room_participants" ("id" INTEGER PRIMARY KEY,"room_id" INTEGER NOT NULL REFERENCES rooms (id),"user_id" INTEGER NOT NULL REFERENCES users (id),- "connection_id" INTEGER,+ "answering_connection_id" INTEGER,"location_kind" INTEGER,"location_project_id" INTEGER REFERENCES projects (id),"initial_project_id" INTEGER REFERENCES projects (id),"calling_user_id" INTEGER NOT NULL REFERENCES users (id)+ "calling_connection_id" INTEGER NOT NULL);CREATE UNIQUE INDEX "index_room_participants_on_user_id" ON "room_participants" ("user_id");diff --git a/crates/collab/migrations/20221111092550_reconnection_support.sql b/crates/collab/migrations/20221111092550_reconnection_support.sqlindex ed6da2b7b14..48e6b50b06c 100644--- a/crates/collab/migrations/20221111092550_reconnection_support.sql+++ b/crates/collab/migrations/20221111092550_reconnection_support.sql@@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS "room_participants" ("location_kind" INTEGER,"location_project_id" INTEGER REFERENCES projects (id),"initial_project_id" INTEGER REFERENCES projects (id),- "calling_user_id" INTEGER NOT NULL REFERENCES users (id)+ "calling_user_id" INTEGER NOT NULL REFERENCES users (id),+ "calling_connection_id" INTEGER NOT NULL);CREATE UNIQUE INDEX "index_room_participants_on_user_id" ON "room_participants" ("user_id");-diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rsindex e092bd95014..3ffdc602dad 100644--- a/crates/collab/src/db.rs+++ b/crates/collab/src/db.rs@@ -1342,7 +1342,7 @@ whereINSERT INTO projects (host_user_id, room_id)VALUES ($1)RETURNING id- ",+ ",).bind(user_id).bind(room_id)@@ -1354,7 +1354,7 @@ wheresqlx::query("INSERT INTO worktrees (id, project_id, root_name)- ",+ ",).bind(worktree.id as i32).bind(project_id)@@ -1741,15 +1741,6 @@ pub struct Room {pub live_kit_room: String,}-#[derive(Clone, Debug, Default, FromRow, PartialEq)]-pub struct Call {- pub room_id: RoomId,- pub calling_user_id: UserId,- pub called_user_id: UserId,- pub answering_connection_id: Option<i32>,- pub initial_project_id: Option<ProjectId>,-}-id_type!(ProjectId);#[derive(Clone, Debug, Default, FromRow, Serialize, PartialEq)]pub struct Project {diff --git a/crates/collab/src/rpc.rs b/crates/collab/src/rpc.rsindex 12219646015..5b713226b18 100644--- a/crates/collab/src/rpc.rs+++ b/crates/collab/src/rpc.rs@@ -431,12 +431,8 @@ impl Server {let mut contacts_to_update = HashSet::default();let mut room_left = None;{- let mut store = self.store().await;-- #[cfg(test)]- let removed_connection = store.remove_connection(connection_id).unwrap();- #[cfg(not(test))]- let removed_connection = store.remove_connection(connection_id)?;+ let removed_connection = self.store().await.remove_connection(connection_id)?;+ self.app_state.db.remove_connection(connection_id);for project in removed_connection.hosted_projects {projects_to_unshare.push(project.id);diff --git a/crates/collab/src/rpc/store.rs b/crates/collab/src/rpc/store.rsindex 4ea2c7b38ef..de444924091 100644--- a/crates/collab/src/rpc/store.rs+++ b/crates/collab/src/rpc/store.rs@@ -72,16 +72,6 @@ pub struct Worktree {pub type ReplicaId = u16;-#[derive(Default)]-pub struct RemovedConnectionState<'a> {- pub user_id: UserId,- pub hosted_projects: Vec<Project>,- pub guest_projects: Vec<LeftProject>,- pub contact_ids: HashSet<UserId>,- pub room: Option<Cow<'a, proto::Room>>,- pub canceled_call_connection_ids: Vec<ConnectionId>,-}-pub struct LeftProject {pub id: ProjectId,pub host_user_id: UserId,@@ -129,47 +119,20 @@ impl Store {}#[instrument(skip(self))]- pub fn remove_connection(- &mut self,- connection_id: ConnectionId,- ) -> Result<RemovedConnectionState> {+ pub fn remove_connection(&mut self, connection_id: ConnectionId) -> Result<()> {let connection = self.connections.get_mut(&connection_id).ok_or_else(|| anyhow!("no such connection"))?;let user_id = connection.user_id;-- let mut result = RemovedConnectionState {- user_id,- ..Default::default()- };-- let connected_user = self.connected_users.get(&user_id).unwrap();- if let Some(active_call) = connected_user.active_call.as_ref() {- let room_id = active_call.room_id;- if active_call.connection_id == Some(connection_id) {- todo!()- // let left_room = self.leave_room(room_id, connection_id)?;- // result.hosted_projects = left_room.unshared_projects;- // result.guest_projects = left_room.left_projects;- // result.room = Some(Cow::Owned(left_room.room.into_owned()));- // result.canceled_call_connection_ids = left_room.canceled_call_connection_ids;- } else if connected_user.connection_ids.len() == 1 {- todo!()- // let (room, _) = self.decline_call(room_id, connection_id)?;- // result.room = Some(Cow::Owned(room.clone()));- }- }-let connected_user = self.connected_users.get_mut(&user_id).unwrap();connected_user.connection_ids.remove(&connection_id);if connected_user.connection_ids.is_empty() {self.connected_users.remove(&user_id);}self.connections.remove(&connection_id).unwrap();-- Ok(result)+ Ok(())}pub fn user_id_for_connection(&self, connection_id: ConnectionId) -> Result<UserId> {