From 5b4ff74dcac678356e6625944bb539c157522c2f Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner <53836821+bennetbo@users.noreply.github.com> Date: Thu, 4 Apr 2024 13:43:14 +0200 Subject: [PATCH] collab ui: Dismiss project shared notifications when leaving room (#10160) When leaving a call/room in which a project was shared, the shared project notification was not getting dismissed when the person that shared the project left the room. Although there was a `cx.emit(Event::Left)` call inside room, the event was never received in the `project_shared_notification` module, because the room is dropped before the event can be dispatched. Moving the `cx.emit(Event::Left)` to the active call fixed the problem. Also renamed `Event::Left` to `Event::RoomLeft` because the room join equivalent is also called `Event::RoomJoined`. Release Notes: - Fixed project shared notification staying open, when the user that shared the project left the room --- crates/call/src/call.rs | 3 +++ crates/call/src/room.rs | 5 +---- crates/collab/src/tests/integration_tests.rs | 18 ++++++++++++++++++ crates/collab_ui/src/chat_panel.rs | 2 +- .../project_shared_notification.rs | 2 +- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/call/src/call.rs b/crates/call/src/call.rs index f0a0a22fb31267f66820fc555c9bf523e8f1c43d..7db9ddfbd93b0be898bb49cb26777c807e4daa9d 100644 --- a/crates/call/src/call.rs +++ b/crates/call/src/call.rs @@ -373,7 +373,10 @@ impl ActiveCall { self.report_call_event("hang up", cx); Audio::end_call(cx); + + let channel_id = self.channel_id(cx); if let Some((room, _)) = self.room.take() { + cx.emit(Event::RoomLeft { channel_id }); room.update(cx, |room, cx| room.leave(cx)) } else { Task::ready(Ok(())) diff --git a/crates/call/src/room.rs b/crates/call/src/room.rs index 5599c15b6d99dbc052bbb79759028f8e267a057f..94c055e6b83f6f82208b71767556e467746b5ad4 100644 --- a/crates/call/src/room.rs +++ b/crates/call/src/room.rs @@ -52,7 +52,7 @@ pub enum Event { RemoteProjectInvitationDiscarded { project_id: u64, }, - Left { + RoomLeft { channel_id: Option, }, } @@ -366,9 +366,6 @@ impl Room { pub(crate) fn leave(&mut self, cx: &mut ModelContext) -> Task> { cx.notify(); - cx.emit(Event::Left { - channel_id: self.channel_id(), - }); self.leave_internal(cx) } diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rs index b15e2b5123d627f1c773f523f0a973b0216ee19e..dbda880b1c64e911f84174c28d106613fd778656 100644 --- a/crates/collab/src/tests/integration_tests.rs +++ b/crates/collab/src/tests/integration_tests.rs @@ -1866,6 +1866,24 @@ async fn test_active_call_events( executor.run_until_parked(); assert_eq!(mem::take(&mut *events_a.borrow_mut()), vec![]); assert_eq!(mem::take(&mut *events_b.borrow_mut()), vec![]); + + // Unsharing a project should dispatch the RemoteProjectUnshared event. + active_call_a + .update(cx_a, |call, cx| call.hang_up(cx)) + .await + .unwrap(); + executor.run_until_parked(); + + assert_eq!( + mem::take(&mut *events_a.borrow_mut()), + vec![room::Event::RoomLeft { channel_id: None }] + ); + assert_eq!( + mem::take(&mut *events_b.borrow_mut()), + vec![room::Event::RemoteProjectUnshared { + project_id: project_a_id, + }] + ); } fn active_call_events(cx: &mut TestAppContext) -> Rc>> { diff --git a/crates/collab_ui/src/chat_panel.rs b/crates/collab_ui/src/chat_panel.rs index f1e3cab3524e9113ab1a97e311b98846edbac5bc..b1dd6584b2cb634474d67c3b327c65d8f6b9bf60 100644 --- a/crates/collab_ui/src/chat_panel.rs +++ b/crates/collab_ui/src/chat_panel.rs @@ -156,7 +156,7 @@ impl ChatPanel { } } } - room::Event::Left { channel_id } => { + room::Event::RoomLeft { channel_id } => { if channel_id == &this.channel_id(cx) { cx.emit(PanelEvent::Close) } diff --git a/crates/collab_ui/src/notifications/project_shared_notification.rs b/crates/collab_ui/src/notifications/project_shared_notification.rs index 46c5c8ce8a61bf45f0ef7643981afcc73318358c..407ff66d19143da3e9737668ad470830682dc3f6 100644 --- a/crates/collab_ui/src/notifications/project_shared_notification.rs +++ b/crates/collab_ui/src/notifications/project_shared_notification.rs @@ -58,7 +58,7 @@ pub fn init(app_state: &Arc, cx: &mut AppContext) { } } - room::Event::Left { .. } => { + room::Event::RoomLeft { .. } => { for (_, windows) in notification_windows.drain() { for window in windows { window