From 6fb5901d69054eadc881c104ff2b4220ff1dd05e Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 7 Oct 2022 14:47:06 +0200 Subject: [PATCH] Ensure sharing the same project twice is idempotent --- crates/call/src/room.rs | 6 ++++++ crates/collab/src/integration_tests.rs | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/crates/call/src/room.rs b/crates/call/src/room.rs index e08d814a3e..1630edb300 100644 --- a/crates/call/src/room.rs +++ b/crates/call/src/room.rs @@ -299,6 +299,12 @@ impl Room { project: ModelHandle, cx: &mut ModelContext, ) -> Task> { + if project.read(cx).is_remote() { + return Task::ready(Err(anyhow!("can't share remote project"))); + } else if let Some(project_id) = project.read(cx).remote_id() { + return Task::ready(Ok(project_id)); + } + let request = self .client .request(proto::ShareProject { room_id: self.id() }); diff --git a/crates/collab/src/integration_tests.rs b/crates/collab/src/integration_tests.rs index 36b9d46d7b..9cde2b2206 100644 --- a/crates/collab/src/integration_tests.rs +++ b/crates/collab/src/integration_tests.rs @@ -838,6 +838,16 @@ async fn test_active_call_events( ); assert_eq!(mem::take(&mut *events_b.borrow_mut()), vec![]); + // Sharing a project twice is idempotent. + let project_b_id_2 = active_call_b + .update(cx_b, |call, cx| call.share_project(project_b.clone(), cx)) + .await + .unwrap(); + assert_eq!(project_b_id_2, project_b_id); + deterministic.run_until_parked(); + assert_eq!(mem::take(&mut *events_a.borrow_mut()), vec![]); + assert_eq!(mem::take(&mut *events_b.borrow_mut()), vec![]); + fn active_call_events(cx: &mut TestAppContext) -> Rc>> { let events = Rc::new(RefCell::new(Vec::new())); let active_call = cx.read(ActiveCall::global);