Fix screen sharing panic introduced by call events

Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Joseph T. Lyons 2023-07-12 16:09:39 -04:00
parent 1e8ee5361d
commit 6da5008f32
2 changed files with 38 additions and 10 deletions

View file

@ -263,7 +263,7 @@ impl ActiveCall {
.borrow_mut()
.take()
.ok_or_else(|| anyhow!("no incoming call"))?;
self.report_call_event_for_room("decline incoming", call.room_id, cx);
Self::report_call_event_for_room("decline incoming", call.room_id, &self.client, cx);
self.client.send(proto::DeclineCall {
room_id: call.room_id,
})?;
@ -373,22 +373,29 @@ impl ActiveCall {
self.room.as_ref().map(|(room, _)| room)
}
pub fn client(&self) -> Arc<Client> {
self.client.clone()
}
pub fn pending_invites(&self) -> &HashSet<u64> {
&self.pending_invites
}
fn report_call_event(&self, operation: &'static str, cx: &AppContext) {
if let Some(room) = self.room() {
self.report_call_event_for_room(operation, room.read(cx).id(), cx)
Self::report_call_event_for_room(operation, room.read(cx).id(), &self.client, cx)
}
}
fn report_call_event_for_room(&self, operation: &'static str, room_id: u64, cx: &AppContext) {
let telemetry = self.client.telemetry();
pub fn report_call_event_for_room(
operation: &'static str,
room_id: u64,
client: &Arc<Client>,
cx: &AppContext,
) {
let telemetry = client.telemetry();
let telemetry_settings = *settings::get::<TelemetrySettings>(cx);
let event = ClickhouseEvent::Call { operation, room_id };
telemetry.report_clickhouse_event(event, telemetry_settings);
}
}

View file

@ -11,7 +11,7 @@ mod sharing_status_indicator;
use call::{ActiveCall, Room};
pub use collab_titlebar_item::{CollabTitlebarItem, ToggleContactsMenu};
use gpui::{actions, AppContext};
use gpui::{actions, AppContext, Task};
use std::sync::Arc;
use util::ResultExt;
use workspace::AppState;
@ -44,9 +44,30 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
}
pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
ActiveCall::global(cx).update(cx, |call, cx| {
call.toggle_screen_sharing(cx);
});
let call = ActiveCall::global(cx).read(cx);
if let Some(room) = call.room().cloned() {
let client = call.client();
let toggle_screen_sharing = room.update(cx, |room, cx| {
if room.is_screen_sharing() {
ActiveCall::report_call_event_for_room(
"disable screen share",
room.id(),
&client,
cx,
);
Task::ready(room.unshare_screen(cx))
} else {
ActiveCall::report_call_event_for_room(
"enable screen share",
room.id(),
&client,
cx,
);
room.share_screen(cx)
}
});
toggle_screen_sharing.detach_and_log_err(cx);
}
}
pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {