| 1 | use std::time::{Duration, Instant}; |
| 2 | |
| 3 | use calling::meeting::LiveMeeting; |
| 4 | use calling::{ |
| 5 | AcceptMode, CallCommand, CallHandle, CallSpec, CallState, CallUpdate, Callee, CameraEffects, |
| 6 | DeviceChoice, EndReason, EngineEvent, MicSettings, MuteCommand, Reaction, RingSignal, ShareSource, VideoKey, |
| 7 | }; |
| 8 | use gpui_kit::*; |
| 9 | |
| 10 | use super::background::{ |
| 11 | BACKGROUND_META_KEY, BackgroundPick, SHOWN_IMAGES, is_image_file, save_custom_backgrounds, |
| 12 | }; |
| 13 | use super::demo::{ |
| 14 | DemoCall, DemoScene, demo_caller, demo_guests, demo_ring, demo_video_ring, start_demo_call, |
| 15 | start_demo_scene_call, |
| 16 | }; |
| 17 | use super::features::{TransferCandidate, room_closed_move}; |
| 18 | use super::media::CallMedia; |
| 19 | use super::mic::save_mic; |
| 20 | use super::end_screen::{CallEndScreen, end_tone}; |
| 21 | use super::model::{ActiveCall, CallKind, CallModel, ConsultTransfer, ended_notice}; |
| 22 | use super::prejoin::{DemoMeeting, MeetingJoin}; |
| 23 | use super::report::{ |
| 24 | CallRecorder, OwnIdentity, SETTING_META_KEY, SharedRecorder, report_directory, save_report, shared, |
| 25 | }; |
| 26 | use super::ring::{MissedCall, RingOutcome}; |
| 27 | use super::target::{is_echo_chat, is_organizer, plan_for_chat}; |
| 28 | use crate::app_state::{AppEvent, AppState, Selection, chat_title, selection_for}; |
| 29 | use crate::notice::NoticeAction; |
| 30 | |
| 31 | const LOBBY_TONE_THROTTLE: Duration = Duration::from_secs(30); |
| 32 | const TIMER_REFRESH: Duration = Duration::from_millis(500); |
| 33 | const SHARE_SOURCES_EVERY_TICKS: u32 = 10; |
| 34 | pub(super) const NOT_CONNECTED_NOTICE: &str = "Not connected to Teams yet"; |
| 35 | const READ_ONLY_NOTICE: &str = "Calls are off in read-only mode"; |
| 36 | const NOT_CALLABLE_NOTICE: &str = "This chat cannot be called"; |
| 37 | pub(super) const MEETING_UNAVAILABLE_NOTICE: &str = "This meeting cannot be joined"; |
| 38 | const ANSWER_FAILED_NOTICE: &str = "Could not answer the call"; |
| 39 | const CONSULT_ENDED_NOTICE: &str = "The consultation ended"; |
| 40 | const DEMO_CONSULT_TARGET: (&str, &str) = ("8:orgid:demo-guest-1", "Jonas Ortega"); |
| 41 | const MEETING_KIND: &str = "meeting"; |
| 42 | const DEMO_LOBBY_MEETING: &str = "demo-chat-meeting-retro"; |
| 43 | const DEMO_CROWD: usize = 11; |
| 44 | const DEMO_SMALL_MEETING: usize = 4; |
| 45 | const DEMO_LIVE_MINUTES: i64 = 60; |
| 46 | const ORGID_PREFIX: &str = "8:orgid:"; |
| 47 | pub const SHARE_SOUND_META_KEY: &str = "call_share_sound"; |
| 48 | const CAMERA_META_KEY: &str = "call_camera"; |
| 49 | const INPUT_META_KEY: &str = "call_input"; |
| 50 | pub fn apply_sound_output(choice: &DeviceChoice) { |
| 51 | let device_key = match choice { |
| 52 | DeviceChoice::SystemDefault => None, |
| 53 | DeviceChoice::Device(device_key) => Some(device_key.clone()), |
| 54 | }; |
| 55 | app_base::notify::platform::set_sound_output(device_key); |
| 56 | } |
| 57 | |
| 58 | const OUTPUT_META_KEY: &str = "call_output"; |
| 59 | const EFFECTS_META_KEY: &str = "call_camera_effects"; |
| 60 | const DEFAULT_DEVICE_META: &str = "default"; |
| 61 | const REPORT_SAVED_NOTICE: &str = "Test report saved"; |
| 62 | |
| 63 | pub fn load_share_sound(store: &store::Store) -> bool { |
| 64 | store.meta(SHARE_SOUND_META_KEY).ok().flatten().as_deref() == Some("1") |
| 65 | } |
| 66 | |
| 67 | pub fn load_camera(store: &store::Store) -> DeviceChoice { |
| 68 | load_device(store, CAMERA_META_KEY) |
| 69 | } |
| 70 | |
| 71 | pub fn load_input(store: &store::Store) -> DeviceChoice { |
| 72 | load_device(store, INPUT_META_KEY) |
| 73 | } |
| 74 | |
| 75 | pub fn load_output(store: &store::Store) -> DeviceChoice { |
| 76 | load_device(store, OUTPUT_META_KEY) |
| 77 | } |
| 78 | |
| 79 | fn load_device(store: &store::Store, key: &str) -> DeviceChoice { |
| 80 | match store.meta(key).ok().flatten() { |
| 81 | Some(key) if !key.is_empty() && key != DEFAULT_DEVICE_META => DeviceChoice::Device(key), |
| 82 | _ => DeviceChoice::SystemDefault, |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | pub fn load_camera_effects(store: &store::Store) -> CameraEffects { |
| 87 | store |
| 88 | .meta(EFFECTS_META_KEY) |
| 89 | .ok() |
| 90 | .flatten() |
| 91 | .map_or_else(CameraEffects::default, |value| { |
| 92 | CameraEffects::from_meta(&value) |
| 93 | }) |
| 94 | } |
| 95 | |
| 96 | fn device_meta(choice: &DeviceChoice) -> &str { |
| 97 | match choice { |
| 98 | DeviceChoice::SystemDefault => DEFAULT_DEVICE_META, |
| 99 | DeviceChoice::Device(key) => key, |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | fn demo_consult_target() -> TransferCandidate { |
| 104 | TransferCandidate { |
| 105 | mri: DEMO_CONSULT_TARGET.0.to_owned(), |
| 106 | name: DEMO_CONSULT_TARGET.1.to_owned(), |
| 107 | user_id: None, |
| 108 | chat_id: "demo-chat-jonas".to_owned(), |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | fn now_unix() -> i64 { |
| 113 | chrono::Utc::now().timestamp() |
| 114 | } |
| 115 | |
| 116 | impl AppState { |
| 117 | pub fn start_test_call(&mut self, cx: &mut Context<Self>) { |
| 118 | if self.call.is_some() { |
| 119 | self.show_call(true, cx); |
| 120 | return; |
| 121 | } |
| 122 | let Some(handle) = self.place_call(CallSpec::Echo, DemoCall::Test, false, cx) else { |
| 123 | return; |
| 124 | }; |
| 125 | self.begin_call(handle, CallModel::test(), None, cx); |
| 126 | } |
| 127 | |
| 128 | pub fn start_chat_call(&mut self, conversation_id: &str, cx: &mut Context<Self>) { |
| 129 | self.start_chat_call_with(conversation_id, false, cx); |
| 130 | } |
| 131 | |
| 132 | pub fn start_chat_video_call(&mut self, conversation_id: &str, cx: &mut Context<Self>) { |
| 133 | self.start_chat_call_with(conversation_id, true, cx); |
| 134 | } |
| 135 | |
| 136 | fn start_chat_call_with( |
| 137 | &mut self, |
| 138 | conversation_id: &str, |
| 139 | with_video: bool, |
| 140 | cx: &mut Context<Self>, |
| 141 | ) { |
| 142 | if self.call.is_some() { |
| 143 | self.show_call(true, cx); |
| 144 | return; |
| 145 | } |
| 146 | let chat = self.sidebar.chats.iter().find(|chat| chat.id == conversation_id); |
| 147 | if chat.is_some_and(is_echo_chat) { |
| 148 | self.start_test_call(cx); |
| 149 | return; |
| 150 | } |
| 151 | let plan = chat.and_then(|chat| plan_for_chat(chat, self.directory.me.as_ref())); |
| 152 | let Some(plan) = plan else { |
| 153 | self.raise_notice(NOT_CALLABLE_NOTICE.to_owned(), None, cx); |
| 154 | return; |
| 155 | }; |
| 156 | let spec = CallSpec::People { |
| 157 | callees: plan |
| 158 | .callees |
| 159 | .iter() |
| 160 | .map(|(mri, name)| Callee { |
| 161 | mri: mri.clone(), |
| 162 | display_name: name.clone(), |
| 163 | }) |
| 164 | .collect(), |
| 165 | thread_id: conversation_id.to_owned(), |
| 166 | }; |
| 167 | let Some(handle) = |
| 168 | self.place_call(spec, DemoCall::People(plan.callees.clone()), with_video, cx) |
| 169 | else { |
| 170 | return; |
| 171 | }; |
| 172 | let user_ids = plan |
| 173 | .callees |
| 174 | .iter() |
| 175 | .filter_map(|(mri, _)| mri.strip_prefix(ORGID_PREFIX).map(str::to_owned)) |
| 176 | .collect(); |
| 177 | self.request_avatars(user_ids, cx); |
| 178 | let model = CallModel::people(&plan.title, &plan.callees); |
| 179 | self.begin_call(handle, model, Some(conversation_id.to_owned()), cx); |
| 180 | if with_video && self.mode.demo { |
| 181 | self.send_call_command(CallCommand::SetCamera(true)); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | pub fn join_meeting_call(&mut self, conversation_id: &str, cx: &mut Context<Self>) { |
| 186 | if self.call.is_some() { |
| 187 | self.show_call(true, cx); |
| 188 | return; |
| 189 | } |
| 190 | let Some(meeting) = self.running_meeting(conversation_id).cloned() else { |
| 191 | self.raise_notice(MEETING_UNAVAILABLE_NOTICE.to_owned(), None, cx); |
| 192 | return; |
| 193 | }; |
| 194 | let Some(target) = meeting.target() else { |
| 195 | self.raise_notice(MEETING_UNAVAILABLE_NOTICE.to_owned(), None, cx); |
| 196 | return; |
| 197 | }; |
| 198 | let demo = DemoMeeting { |
| 199 | guests: if conversation_id == DEMO_LOBBY_MEETING { |
| 200 | DEMO_SMALL_MEETING |
| 201 | } else { |
| 202 | DEMO_CROWD |
| 203 | }, |
| 204 | lobby: conversation_id == DEMO_LOBBY_MEETING, |
| 205 | organizer: conversation_id != DEMO_LOBBY_MEETING, |
| 206 | }; |
| 207 | let title = selection_for(&self.sidebar, conversation_id) |
| 208 | .map(|selection| crate::app_state::selection_title(&self.sidebar, &selection)) |
| 209 | .unwrap_or_else(|| "Meeting".to_owned()); |
| 210 | let join = MeetingJoin { |
| 211 | organizer: is_organizer(&meeting, self.directory.me.as_ref()), |
| 212 | conversation_id: Some(conversation_id.to_owned()), |
| 213 | target, |
| 214 | title, |
| 215 | demo, |
| 216 | }; |
| 217 | self.stage_meeting_join(join, cx); |
| 218 | } |
| 219 | |
| 220 | pub(super) fn place_call( |
| 221 | &mut self, |
| 222 | spec: CallSpec, |
| 223 | demo: DemoCall, |
| 224 | with_video: bool, |
| 225 | cx: &mut Context<Self>, |
| 226 | ) -> Option<CallHandle> { |
| 227 | if self.mode.demo { |
| 228 | return Some(start_demo_call(demo)); |
| 229 | } |
| 230 | if self.mode.read_only { |
| 231 | self.raise_notice(READ_ONLY_NOTICE.to_owned(), None, cx); |
| 232 | return None; |
| 233 | } |
| 234 | match self.call_launcher.clone() { |
| 235 | Some(launcher) if with_video => Some(launcher.start_video_call(spec)), |
| 236 | Some(launcher) => Some(launcher.start_call(spec)), |
| 237 | None => { |
| 238 | self.raise_notice(NOT_CONNECTED_NOTICE.to_owned(), None, cx); |
| 239 | None |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | pub(super) fn begin_call( |
| 245 | &mut self, |
| 246 | handle: CallHandle, |
| 247 | model: CallModel, |
| 248 | conversation_id: Option<String>, |
| 249 | cx: &mut Context<Self>, |
| 250 | ) { |
| 251 | self.call_count += 1; |
| 252 | let call_id = self.call_count; |
| 253 | self.call_end = None; |
| 254 | let CallHandle { |
| 255 | commands, |
| 256 | updates, |
| 257 | video, |
| 258 | } = handle; |
| 259 | self.call = Some(ActiveCall::new( |
| 260 | call_id, |
| 261 | model, |
| 262 | commands, |
| 263 | conversation_id, |
| 264 | video, |
| 265 | )); |
| 266 | if self.call_share_sound { |
| 267 | self.send_call_command(CallCommand::SetShareSound(true)); |
| 268 | } |
| 269 | if self.call_share_motion { |
| 270 | self.send_call_command(CallCommand::SetShareMotion(true)); |
| 271 | } |
| 272 | if self.call_share_standout { |
| 273 | self.send_call_command(CallCommand::SetShareStandout(true)); |
| 274 | } |
| 275 | if self.call_mic != MicSettings::default() { |
| 276 | self.send_call_command(CallCommand::SetMicSettings(self.call_mic)); |
| 277 | } |
| 278 | if let Some(call) = self.call.as_mut() { |
| 279 | call.model.background = self.call_background.clone(); |
| 280 | call.model.camera = self.call_camera.clone(); |
| 281 | call.model.view = self.call_view; |
| 282 | call.model.refresh_layout(Instant::now()); |
| 283 | } |
| 284 | if self.call_camera != DeviceChoice::SystemDefault { |
| 285 | self.send_call_command(CallCommand::SelectCamera(self.call_camera.clone())); |
| 286 | } |
| 287 | if self.call_input != DeviceChoice::SystemDefault { |
| 288 | self.send_call_command(CallCommand::SelectInput(self.call_input.clone())); |
| 289 | } |
| 290 | if self.call_output != DeviceChoice::SystemDefault { |
| 291 | self.send_call_command(CallCommand::SelectOutput(self.call_output.clone())); |
| 292 | } |
| 293 | if self.call_background != BackgroundPick::None { |
| 294 | self.send_background_command(cx); |
| 295 | } |
| 296 | self.send_call_command(CallCommand::SetCameraEffects(self.call_effects)); |
| 297 | self.refresh_call_backgrounds(cx); |
| 298 | self.new_chat = false; |
| 299 | let report = self.start_call_report(); |
| 300 | if let Some(call) = self.call.as_mut() { |
| 301 | call.report.clone_from(&report); |
| 302 | } |
| 303 | let rights_conversation = self.call.as_ref().and_then(|call| call.conversation_id.clone()); |
| 304 | self.apply_recording_rights(rights_conversation.as_deref(), cx); |
| 305 | self.follow_call(call_id, updates, report, cx); |
| 306 | cx.emit(AppEvent::Call); |
| 307 | cx.notify(); |
| 308 | } |
| 309 | |
| 310 | fn start_call_report(&self) -> Option<SharedRecorder> { |
| 311 | let call = self.call.as_ref().filter(|_| self.call_report_enabled)?; |
| 312 | let me = self.directory.me.as_ref(); |
| 313 | let own = OwnIdentity { |
| 314 | mri: me.map_or_else(String::new, |me| format!("{ORGID_PREFIX}{}", me.user_id)), |
| 315 | display_name: me.map_or_else(String::new, |me| me.display_name.clone()), |
| 316 | email: self.own_email.clone(), |
| 317 | }; |
| 318 | let mut people: Vec<(String, String)> = call |
| 319 | .model |
| 320 | .tiles |
| 321 | .iter() |
| 322 | .map(|tile| (tile.mri.clone(), tile.name.clone())) |
| 323 | .collect(); |
| 324 | if people.is_empty() { |
| 325 | people.push((String::new(), call.model.peer_name.clone())); |
| 326 | } |
| 327 | let recorder = CallRecorder::begin( |
| 328 | call.model.kind, |
| 329 | call.model.incoming, |
| 330 | self.mode.demo, |
| 331 | own, |
| 332 | people, |
| 333 | ); |
| 334 | Some(shared(recorder)) |
| 335 | } |
| 336 | |
| 337 | pub(super) fn note_call_feature(&self, feature: &'static str, detail: String) { |
| 338 | if let Some(report) = self.call.as_ref().and_then(|call| call.report.as_ref()) { |
| 339 | report.borrow_mut().local_feature(feature, detail); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | fn report_saved(&mut self, path: std::path::PathBuf, cx: &mut Context<Self>) { |
| 344 | let action = NoticeAction::new("Open folder", move |_, _| { |
| 345 | crate::downloads::reveal_in_file_manager(&path) |
| 346 | }); |
| 347 | let text = match self.notice.as_ref().filter(|notice| notice.action.is_none()) { |
| 348 | Some(ended) => format!("{}. {REPORT_SAVED_NOTICE}", ended.text.trim_end_matches('.')), |
| 349 | None => REPORT_SAVED_NOTICE.to_owned(), |
| 350 | }; |
| 351 | self.raise_notice(text, Some(action), cx); |
| 352 | } |
| 353 | |
| 354 | pub fn set_call_report_enabled(&mut self, on: bool, cx: &mut Context<Self>) { |
| 355 | self.call_report_enabled = on; |
| 356 | let _ = self.store.set_meta(SETTING_META_KEY, if on { "1" } else { "0" }); |
| 357 | cx.notify(); |
| 358 | } |
| 359 | |
| 360 | fn follow_call( |
| 361 | &mut self, |
| 362 | call_id: u64, |
| 363 | mut updates: tokio::sync::mpsc::UnboundedReceiver<CallUpdate>, |
| 364 | report: Option<SharedRecorder>, |
| 365 | cx: &mut Context<Self>, |
| 366 | ) { |
| 367 | cx.spawn(async move |this, cx| { |
| 368 | while let Some(update) = updates.recv().await { |
| 369 | if let Some(report) = &report { |
| 370 | report.borrow_mut().observe(&update); |
| 371 | } |
| 372 | let alive = |
| 373 | this.update(cx, |state, cx| state.apply_call_update(call_id, update, cx)); |
| 374 | if alive.is_err() { |
| 375 | return; |
| 376 | } |
| 377 | } |
| 378 | let _ = this.update(cx, |state, cx| state.end_orphaned_call(call_id, cx)); |
| 379 | let Some(report) = report else { |
| 380 | return; |
| 381 | }; |
| 382 | let reason = EndReason::Failed("The call stopped unexpectedly".to_owned()); |
| 383 | report.borrow_mut().observe(&CallUpdate::State(CallState::Ended { reason })); |
| 384 | let recorder = report.borrow().clone(); |
| 385 | let saved = cx |
| 386 | .background_executor() |
| 387 | .spawn(async move { save_report(&report_directory(), &recorder.document()) }) |
| 388 | .await; |
| 389 | match saved { |
| 390 | Ok(saved) => { |
| 391 | let _ = this.update(cx, |state, cx| state.report_saved(saved.json, cx)); |
| 392 | } |
| 393 | Err(error) => log::warn!("call test report not saved: {error}"), |
| 394 | } |
| 395 | }) |
| 396 | .detach(); |
| 397 | cx.spawn(async move |this, cx| { |
| 398 | let mut ticks = 0u32; |
| 399 | loop { |
| 400 | cx.background_executor().timer(TIMER_REFRESH).await; |
| 401 | ticks += 1; |
| 402 | let running = this.update(cx, |state, cx| { |
| 403 | let visible = state.call.as_ref().is_some_and(|call| call.id == call_id); |
| 404 | if visible { |
| 405 | if ticks.is_multiple_of(SHARE_SOURCES_EVERY_TICKS) { |
| 406 | state.refresh_share_sources(); |
| 407 | } |
| 408 | state.tick_call_layout(cx); |
| 409 | CallMedia::changed(&state.call_media, cx); |
| 410 | } |
| 411 | visible || state.is_held_call(call_id) |
| 412 | }); |
| 413 | if !running.unwrap_or(false) { |
| 414 | return; |
| 415 | } |
| 416 | } |
| 417 | }) |
| 418 | .detach(); |
| 419 | } |
| 420 | |
| 421 | fn end_orphaned_call(&mut self, call_id: u64, cx: &mut Context<Self>) { |
| 422 | let still_open = self |
| 423 | .call |
| 424 | .iter() |
| 425 | .chain(&self.held_call) |
| 426 | .any(|call| call.id == call_id && call.model.is_active()); |
| 427 | if still_open { |
| 428 | let reason = EndReason::Failed("The call stopped unexpectedly".to_owned()); |
| 429 | self.apply_call_update(call_id, CallUpdate::State(CallState::Ended { reason }), cx); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | fn with_known_names(&self, update: CallUpdate) -> CallUpdate { |
| 434 | let mut entries = match update { |
| 435 | CallUpdate::Roster(entries) => entries, |
| 436 | other => return other, |
| 437 | }; |
| 438 | let user_id = |entry: &calling::RosterEntry| entry.mri.strip_prefix(ORGID_PREFIX).map(str::to_owned); |
| 439 | let missing: Vec<String> = entries |
| 440 | .iter() |
| 441 | .filter(|entry| entry.display_name.is_empty()) |
| 442 | .filter_map(user_id) |
| 443 | .collect(); |
| 444 | if !missing.is_empty() { |
| 445 | let names = crate::people::resolve_names(self, &missing); |
| 446 | for entry in entries.iter_mut().filter(|entry| entry.display_name.is_empty()) { |
| 447 | if let Some(name) = user_id(entry).and_then(|id| names.get(&id)) { |
| 448 | entry.display_name = name.clone(); |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | CallUpdate::Roster(entries) |
| 453 | } |
| 454 | |
| 455 | pub(super) fn apply_call_update( |
| 456 | &mut self, |
| 457 | call_id: u64, |
| 458 | update: CallUpdate, |
| 459 | cx: &mut Context<Self>, |
| 460 | ) { |
| 461 | let update = self.with_known_names(update); |
| 462 | if self.is_held_call(call_id) { |
| 463 | self.apply_held_call_update(update, cx); |
| 464 | return; |
| 465 | } |
| 466 | let media = self.call_media.clone(); |
| 467 | let Some(call) = self.call.as_mut().filter(|call| call.id == call_id) else { |
| 468 | return; |
| 469 | }; |
| 470 | match update { |
| 471 | CallUpdate::VideoReady => { |
| 472 | call.pictures.apply(&call.video, cx); |
| 473 | CallMedia::changed(&media, cx); |
| 474 | return; |
| 475 | } |
| 476 | CallUpdate::Stats { .. } => return, |
| 477 | CallUpdate::Levels { local, remote } => { |
| 478 | let before = (call.model.local_speaking, call.model.remote_speaking); |
| 479 | call.model.apply(CallUpdate::Levels { local, remote }); |
| 480 | if before != (call.model.local_speaking, call.model.remote_speaking) { |
| 481 | CallMedia::changed(&media, cx); |
| 482 | } |
| 483 | return; |
| 484 | } |
| 485 | CallUpdate::Notice(text) => { |
| 486 | self.raise_notice(text, None, cx); |
| 487 | return; |
| 488 | } |
| 489 | CallUpdate::WhiteboardUrl(url) => { |
| 490 | cx.open_url(&url); |
| 491 | return; |
| 492 | } |
| 493 | CallUpdate::BreakoutMove(moved) => { |
| 494 | self.begin_breakout_move(moved, cx); |
| 495 | return; |
| 496 | } |
| 497 | CallUpdate::MeetingOptions(result) => { |
| 498 | if let Some(dialog) = call.options_dialog.as_mut() { |
| 499 | dialog.loaded(result); |
| 500 | } |
| 501 | cx.notify(); |
| 502 | return; |
| 503 | } |
| 504 | CallUpdate::ReplacementLink(replacement) => { |
| 505 | if let Some(consult) = call.consult.as_mut() { |
| 506 | consult.replacement = Some(replacement); |
| 507 | cx.notify(); |
| 508 | } |
| 509 | return; |
| 510 | } |
| 511 | CallUpdate::MeetingOptionsSaved(result) => { |
| 512 | if call.options_dialog.as_mut().is_some_and(|dialog| dialog.saved(result)) { |
| 513 | call.options_dialog = None; |
| 514 | } |
| 515 | cx.notify(); |
| 516 | return; |
| 517 | } |
| 518 | _ => {} |
| 519 | } |
| 520 | if let (CallUpdate::Caption(entry), Some(thread)) = (&update, call.chat_thread()) { |
| 521 | let speaker = if entry.display_name.is_empty() { |
| 522 | "Someone" |
| 523 | } else { |
| 524 | &entry.display_name |
| 525 | }; |
| 526 | crate::agent_api::note_caption(thread, &entry.id, speaker, &entry.text, cx); |
| 527 | } |
| 528 | let sharer_before = call.model.screen_sharer.clone(); |
| 529 | let lobby_before = call.model.lobby_mris(); |
| 530 | call.model.apply(update); |
| 531 | if call.model.someone_entered_the_lobby(&lobby_before) |
| 532 | && call |
| 533 | .lobby_tone_at |
| 534 | .is_none_or(|played_at| played_at.elapsed() >= LOBBY_TONE_THROTTLE) |
| 535 | { |
| 536 | call.lobby_tone_at = Some(Instant::now()); |
| 537 | cx.emit(AppEvent::CallTone(chatsvc::sounds::CallTone::MeetingReminder)); |
| 538 | } |
| 539 | if call.model.screen_sharer != sharer_before { |
| 540 | call.pictures.forget(&VideoKey::Screen, cx); |
| 541 | } |
| 542 | if let Some(language) = call.model.take_ready_caption_language() { |
| 543 | let _ = call.commands.send(CallCommand::SetCaptionLanguage(language)); |
| 544 | } |
| 545 | if call.model.screen_sharer.is_none() { |
| 546 | call.stage_fullscreen = false; |
| 547 | call.share_stage.end(); |
| 548 | call.pictures.forget(&VideoKey::Screen, cx); |
| 549 | } |
| 550 | if !call.model.camera_on { |
| 551 | call.pictures.forget(&VideoKey::LocalCamera, cx); |
| 552 | } |
| 553 | let Some(reason) = call.model.ended_reason().cloned() else { |
| 554 | cx.emit(AppEvent::Call); |
| 555 | cx.notify(); |
| 556 | return; |
| 557 | }; |
| 558 | let elapsed = call.model.elapsed(Instant::now()); |
| 559 | let consult = call.consult.take(); |
| 560 | let notice = match &consult { |
| 561 | Some(consult) if consult.transfer == ConsultTransfer::Done => { |
| 562 | format!("Call transferred to {}", consult.target.1) |
| 563 | } |
| 564 | Some(_) if self.held_call.is_some() => CONSULT_ENDED_NOTICE.to_owned(), |
| 565 | _ => ended_notice(&reason, elapsed, &call.model.peer_name), |
| 566 | }; |
| 567 | let back_to_held = consult |
| 568 | .as_ref() |
| 569 | .is_some_and(|consult| consult.transfer != ConsultTransfer::Done); |
| 570 | let next_move = call |
| 571 | .pending_move |
| 572 | .take() |
| 573 | .or_else(|| room_closed_move(call, &reason)); |
| 574 | if let Some(tone) = end_tone(call.model.kind, next_move.is_some()) { |
| 575 | cx.emit(AppEvent::CallTone(tone)); |
| 576 | } |
| 577 | let end_screen = (call.viewing && !back_to_held && next_move.is_none()) |
| 578 | .then(|| CallEndScreen::for_call(call, &reason)) |
| 579 | .flatten(); |
| 580 | call.pictures.clear(cx); |
| 581 | if let Some(thread) = call.chat_thread() { |
| 582 | crate::agent_api::clear_captions(thread, cx); |
| 583 | } |
| 584 | self.call = None; |
| 585 | self.transcript_panel = None; |
| 586 | if back_to_held { |
| 587 | self.call = self.held_call.take(); |
| 588 | } |
| 589 | match (next_move, end_screen) { |
| 590 | (Some(next_move), _) => self.join_moved_call(next_move, cx), |
| 591 | (None, Some(end_screen)) => self.call_end = Some(end_screen), |
| 592 | (None, None) => self.raise_notice(notice, None, cx), |
| 593 | } |
| 594 | self.refresh_call_history_after_call(cx); |
| 595 | cx.emit(AppEvent::Call); |
| 596 | cx.notify(); |
| 597 | } |
| 598 | |
| 599 | pub(super) fn send_call_command(&self, command: CallCommand) { |
| 600 | if let Some(call) = &self.call { |
| 601 | if let Some(report) = &call.report { |
| 602 | report.borrow_mut().command(&command); |
| 603 | } |
| 604 | let _ = call.commands.send(command); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | pub fn toggle_call_mute(&mut self, _cx: &mut Context<Self>) { |
| 609 | let can_toggle = self |
| 610 | .call |
| 611 | .as_ref() |
| 612 | .is_some_and(|call| call.model.can_unmute()); |
| 613 | if can_toggle { |
| 614 | self.send_call_command(CallCommand::Mute(MuteCommand::Toggle)); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | pub fn toggle_call_camera(&mut self, _cx: &mut Context<Self>) { |
| 619 | let Some(call) = self |
| 620 | .call |
| 621 | .as_ref() |
| 622 | .filter(|call| call.model.can_use_camera()) |
| 623 | else { |
| 624 | return; |
| 625 | }; |
| 626 | let on = !call.model.camera_on; |
| 627 | self.send_call_command(CallCommand::SetCamera(on)); |
| 628 | } |
| 629 | |
| 630 | pub fn set_call_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) { |
| 631 | self.call_mic = settings; |
| 632 | save_mic(&self.store, settings); |
| 633 | self.send_call_command(CallCommand::SetMicSettings(settings)); |
| 634 | cx.notify(); |
| 635 | } |
| 636 | |
| 637 | pub fn press_push_to_talk(&mut self, _cx: &mut Context<Self>) { |
| 638 | let Some(call) = self.call.as_mut() else { |
| 639 | return; |
| 640 | }; |
| 641 | let command = call |
| 642 | .push_to_talk |
| 643 | .press(call.model.muted, call.model.can_unmute()); |
| 644 | if let Some(command) = command { |
| 645 | self.send_call_command(CallCommand::Mute(command)); |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | pub fn release_push_to_talk(&mut self, _cx: &mut Context<Self>) { |
| 650 | let command = self |
| 651 | .call |
| 652 | .as_mut() |
| 653 | .and_then(|call| call.push_to_talk.release()); |
| 654 | if let Some(command) = command { |
| 655 | self.send_call_command(CallCommand::Mute(command)); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | pub fn select_call_camera(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) { |
| 660 | let _ = self.store.set_meta(CAMERA_META_KEY, device_meta(&choice)); |
| 661 | self.call_camera = choice.clone(); |
| 662 | if let Some(launcher) = &self.call_launcher { |
| 663 | launcher.set_default_camera(choice.clone()); |
| 664 | } |
| 665 | if let Some(call) = self.call.as_mut() { |
| 666 | call.model.camera = choice.clone(); |
| 667 | } |
| 668 | self.send_call_command(CallCommand::SelectCamera(choice)); |
| 669 | } |
| 670 | |
| 671 | pub fn start_call_share(&mut self, source: ShareSource, _cx: &mut Context<Self>) { |
| 672 | self.send_call_command(CallCommand::StartShare(source)); |
| 673 | } |
| 674 | |
| 675 | pub fn stop_call_share(&mut self, _cx: &mut Context<Self>) { |
| 676 | self.send_call_command(CallCommand::StopShare); |
| 677 | } |
| 678 | |
| 679 | pub fn refresh_share_sources(&self) { |
| 680 | let idle = self |
| 681 | .call |
| 682 | .as_ref() |
| 683 | .is_some_and(|call| call.model.local_share.is_none()); |
| 684 | if idle { |
| 685 | self.send_call_command(CallCommand::RefreshShareSources); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | pub fn leave_call(&mut self, _cx: &mut Context<Self>) { |
| 690 | self.send_call_command(CallCommand::Hangup); |
| 691 | } |
| 692 | |
| 693 | pub fn end_meeting_for_all(&mut self, _cx: &mut Context<Self>) { |
| 694 | let allowed = self |
| 695 | .call |
| 696 | .as_ref() |
| 697 | .is_some_and(|call| call.model.can_end_meeting); |
| 698 | if allowed { |
| 699 | self.send_call_command(CallCommand::EndMeeting); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | pub fn select_call_input(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) { |
| 704 | let _ = self.store.set_meta(INPUT_META_KEY, device_meta(&choice)); |
| 705 | self.call_input = choice.clone(); |
| 706 | self.send_call_command(CallCommand::SelectInput(choice)); |
| 707 | } |
| 708 | |
| 709 | pub fn select_call_output(&mut self, choice: DeviceChoice, _cx: &mut Context<Self>) { |
| 710 | let _ = self.store.set_meta(OUTPUT_META_KEY, device_meta(&choice)); |
| 711 | self.call_output = choice.clone(); |
| 712 | apply_sound_output(&choice); |
| 713 | self.send_call_command(CallCommand::SelectOutput(choice)); |
| 714 | } |
| 715 | |
| 716 | pub fn show_call(&mut self, viewing: bool, cx: &mut Context<Self>) { |
| 717 | let Some(call) = self.call.as_mut().filter(|call| call.viewing != viewing) else { |
| 718 | return; |
| 719 | }; |
| 720 | call.viewing = viewing; |
| 721 | if viewing { |
| 722 | self.new_chat = false; |
| 723 | } |
| 724 | cx.emit(AppEvent::Call); |
| 725 | cx.notify(); |
| 726 | } |
| 727 | |
| 728 | pub fn toggle_call_chat(&mut self, cx: &mut Context<Self>) { |
| 729 | let Some(call) = self |
| 730 | .call |
| 731 | .as_mut() |
| 732 | .filter(|call| call.chat_thread().is_some()) |
| 733 | else { |
| 734 | return; |
| 735 | }; |
| 736 | call.chat_open = !call.chat_open; |
| 737 | let chat_state = if call.chat_open { "open" } else { "close" }; |
| 738 | if call.chat_open { |
| 739 | call.transcript_open = false; |
| 740 | self.transcript_panel = None; |
| 741 | call.people_open = false; |
| 742 | } |
| 743 | self.note_call_feature("chat", chat_state.to_owned()); |
| 744 | cx.emit(AppEvent::Call); |
| 745 | cx.notify(); |
| 746 | } |
| 747 | |
| 748 | pub fn call_chat_thread(&self) -> Option<String> { |
| 749 | let call = self.call.as_ref().filter(|call| call.chat_open)?; |
| 750 | call.chat_thread().map(str::to_owned) |
| 751 | } |
| 752 | |
| 753 | pub fn call_chat_unread(&self) -> u32 { |
| 754 | let Some(thread) = self |
| 755 | .call |
| 756 | .as_ref() |
| 757 | .filter(|call| !call.chat_open) |
| 758 | .and_then(|call| call.chat_thread()) |
| 759 | else { |
| 760 | return 0; |
| 761 | }; |
| 762 | let counted = self.directory.unread_counts.get(thread).copied(); |
| 763 | counted.unwrap_or_else(|| { |
| 764 | u32::from( |
| 765 | self.sidebar |
| 766 | .chats |
| 767 | .iter() |
| 768 | .any(|chat| chat.id == thread && chat.unread), |
| 769 | ) |
| 770 | }) |
| 771 | } |
| 772 | |
| 773 | pub fn toggle_call_hand(&mut self, cx: &mut Context<Self>) { |
| 774 | let Some(call) = self |
| 775 | .call |
| 776 | .as_mut() |
| 777 | .filter(|call| call.model.is_active() && call.model.has_reaction_controls()) |
| 778 | else { |
| 779 | return; |
| 780 | }; |
| 781 | let raised = call.model.own_hand.is_none(); |
| 782 | call.model.own_hand = raised.then_some(u64::MAX); |
| 783 | self.send_call_command(CallCommand::SetHand(raised)); |
| 784 | if raised { |
| 785 | self.raise_notice("Your hand is raised".to_owned(), None, cx); |
| 786 | } |
| 787 | cx.emit(AppEvent::Call); |
| 788 | cx.notify(); |
| 789 | } |
| 790 | |
| 791 | pub fn lower_call_hand(&mut self, mri: String, _cx: &mut Context<Self>) { |
| 792 | let allowed = self |
| 793 | .call |
| 794 | .as_ref() |
| 795 | .is_some_and(|call| call.model.can_lower_hands()); |
| 796 | if allowed { |
| 797 | self.send_call_command(CallCommand::LowerHand { mri }); |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | pub fn lower_all_call_hands(&mut self, _cx: &mut Context<Self>) { |
| 802 | let allowed = self |
| 803 | .call |
| 804 | .as_ref() |
| 805 | .is_some_and(|call| call.model.can_lower_hands() && call.model.any_hand_raised()); |
| 806 | if allowed { |
| 807 | self.send_call_command(CallCommand::LowerAllHands); |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | pub fn send_call_reaction(&mut self, reaction: Reaction, cx: &mut Context<Self>) { |
| 812 | let Some(call) = self |
| 813 | .call |
| 814 | .as_mut() |
| 815 | .filter(|call| call.model.is_active() && call.model.has_reaction_controls()) |
| 816 | else { |
| 817 | return; |
| 818 | }; |
| 819 | if let Some(own_mri) = call.model.own_mri.clone() { |
| 820 | call.model.note_reaction(own_mri, reaction.clone(), Instant::now()); |
| 821 | } |
| 822 | self.send_call_command(CallCommand::SendReaction(reaction)); |
| 823 | cx.emit(AppEvent::Call); |
| 824 | cx.notify(); |
| 825 | } |
| 826 | |
| 827 | pub fn set_call_share_sound(&mut self, on: bool, cx: &mut Context<Self>) { |
| 828 | self.call_share_sound = on; |
| 829 | let _ = self |
| 830 | .store |
| 831 | .set_meta(SHARE_SOUND_META_KEY, if on { "1" } else { "0" }); |
| 832 | self.send_call_command(CallCommand::SetShareSound(on)); |
| 833 | cx.notify(); |
| 834 | } |
| 835 | |
| 836 | pub fn admit_call_guest(&mut self, mri: String, _cx: &mut Context<Self>) { |
| 837 | if self |
| 838 | .call |
| 839 | .as_ref() |
| 840 | .is_some_and(|call| call.model.can_admit()) |
| 841 | { |
| 842 | self.send_call_command(CallCommand::Admit { mri }); |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | pub fn admit_all_call_guests(&mut self, _cx: &mut Context<Self>) { |
| 847 | if self |
| 848 | .call |
| 849 | .as_ref() |
| 850 | .is_some_and(|call| call.model.can_admit() && !call.model.lobby_guests().is_empty()) |
| 851 | { |
| 852 | self.send_call_command(CallCommand::AdmitAll); |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | pub fn deny_call_guest(&mut self, mri: String, _cx: &mut Context<Self>) { |
| 857 | if self |
| 858 | .call |
| 859 | .as_ref() |
| 860 | .is_some_and(|call| call.model.can_admit()) |
| 861 | { |
| 862 | self.send_call_command(CallCommand::Deny { mri }); |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | pub fn mute_call_participant(&mut self, mri: String, _cx: &mut Context<Self>) { |
| 867 | if self |
| 868 | .call |
| 869 | .as_ref() |
| 870 | .is_some_and(|call| call.model.can_manage()) |
| 871 | { |
| 872 | self.send_call_command(CallCommand::MuteParticipant { mri }); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | pub fn mute_all_call(&mut self, _cx: &mut Context<Self>) { |
| 877 | if self |
| 878 | .call |
| 879 | .as_ref() |
| 880 | .is_some_and(|call| call.model.can_manage()) |
| 881 | { |
| 882 | self.send_call_command(CallCommand::MuteAll); |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | pub fn remove_call_participant(&mut self, mri: String, _cx: &mut Context<Self>) { |
| 887 | if self |
| 888 | .call |
| 889 | .as_ref() |
| 890 | .is_some_and(|call| call.model.can_manage()) |
| 891 | { |
| 892 | self.send_call_command(CallCommand::RemoveParticipant { mri }); |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | pub fn toggle_call_spotlight(&mut self, mri: String, _cx: &mut Context<Self>) { |
| 897 | let Some(call) = self |
| 898 | .call |
| 899 | .as_ref() |
| 900 | .filter(|call| call.model.can_manage() && call.model.is_active()) |
| 901 | else { |
| 902 | return; |
| 903 | }; |
| 904 | let command = if call.model.is_spotlighted(&mri) { |
| 905 | CallCommand::StopSpotlight { mri } |
| 906 | } else { |
| 907 | CallCommand::Spotlight { mri } |
| 908 | }; |
| 909 | self.send_call_command(command); |
| 910 | } |
| 911 | |
| 912 | pub fn toggle_call_pin(&mut self, mri: &str, cx: &mut Context<Self>) { |
| 913 | if let Some(call) = self.call.as_mut() { |
| 914 | call.model.toggle_pin(mri); |
| 915 | cx.notify(); |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | pub fn toggle_call_fit(&mut self, mri: &str, cx: &mut Context<Self>) { |
| 920 | if let Some(call) = self.call.as_mut() { |
| 921 | call.model.toggle_fit(mri); |
| 922 | cx.notify(); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | pub fn toggle_call_captions(&mut self, _cx: &mut Context<Self>) { |
| 927 | let Some(call) = self |
| 928 | .call |
| 929 | .as_ref() |
| 930 | .filter(|call| call.model.is_active() && call.model.kind == CallKind::Meeting) |
| 931 | else { |
| 932 | return; |
| 933 | }; |
| 934 | let on = !call.model.captions_on(); |
| 935 | self.send_call_command(CallCommand::SetCaptions(on)); |
| 936 | } |
| 937 | |
| 938 | pub fn set_call_effects(&mut self, effects: CameraEffects, cx: &mut Context<Self>) { |
| 939 | let _ = self.store.set_meta(EFFECTS_META_KEY, &effects.to_meta()); |
| 940 | self.call_effects = effects; |
| 941 | self.send_call_command(CallCommand::SetCameraEffects(effects)); |
| 942 | cx.notify(); |
| 943 | } |
| 944 | |
| 945 | pub fn set_call_background(&mut self, pick: BackgroundPick, cx: &mut Context<Self>) { |
| 946 | let _ = self.store.set_meta(BACKGROUND_META_KEY, &pick.to_meta()); |
| 947 | self.call_background = pick.clone(); |
| 948 | if let Some(call) = self.call.as_mut() { |
| 949 | call.model.background = pick; |
| 950 | } |
| 951 | self.send_background_command(cx); |
| 952 | cx.notify(); |
| 953 | } |
| 954 | |
| 955 | pub fn toggle_call_background_blur(&mut self, cx: &mut Context<Self>) { |
| 956 | if self.call.is_none() { |
| 957 | return; |
| 958 | } |
| 959 | let pick = if self.call_background == BackgroundPick::Blur { |
| 960 | BackgroundPick::None |
| 961 | } else { |
| 962 | BackgroundPick::Blur |
| 963 | }; |
| 964 | self.set_call_background(pick, cx); |
| 965 | } |
| 966 | |
| 967 | pub(super) fn send_background_command(&mut self, cx: &mut Context<Self>) { |
| 968 | let pick = self.call_background.clone(); |
| 969 | if let Some(choice) = self.call_backgrounds.choice_for(&pick) { |
| 970 | self.send_call_command(CallCommand::SetBackground(choice)); |
| 971 | return; |
| 972 | } |
| 973 | let BackgroundPick::Default(id) = pick else { |
| 974 | return; |
| 975 | }; |
| 976 | let Some(image) = self.call_backgrounds.find(&id).cloned() else { |
| 977 | return; |
| 978 | }; |
| 979 | let Some(launcher) = self.call_launcher.clone() else { |
| 980 | return; |
| 981 | }; |
| 982 | let cache = self.call_backgrounds.cache.clone(); |
| 983 | let receiver = |
| 984 | crate::runtime::spawn( |
| 985 | async move { launcher.download_background(&cache, &image).await }, |
| 986 | ); |
| 987 | cx.spawn(async move |this, cx| { |
| 988 | let path = receiver.await.ok().flatten(); |
| 989 | this.update(cx, |state, cx| match path { |
| 990 | Some(path) if state.call_background == BackgroundPick::Default(id) => { |
| 991 | state.send_call_command(CallCommand::SetBackground( |
| 992 | calling::BackgroundChoice::Image(path), |
| 993 | )); |
| 994 | } |
| 995 | Some(_) => {} |
| 996 | None => state.raise_notice( |
| 997 | "That background could not be downloaded".to_owned(), |
| 998 | None, |
| 999 | cx, |
| 1000 | ), |
| 1001 | }) |
| 1002 | .ok(); |
| 1003 | }) |
| 1004 | .detach(); |
| 1005 | } |
| 1006 | |
| 1007 | pub fn refresh_call_backgrounds(&mut self, cx: &mut Context<Self>) { |
| 1008 | if self.mode.demo || !self.call_backgrounds.needs_refresh() { |
| 1009 | return; |
| 1010 | } |
| 1011 | let Some(launcher) = self.call_launcher.clone() else { |
| 1012 | return; |
| 1013 | }; |
| 1014 | self.call_backgrounds.refreshing = true; |
| 1015 | let cache = self.call_backgrounds.cache.clone(); |
| 1016 | let wanted = SHOWN_IMAGES; |
| 1017 | let receiver = |
| 1018 | crate::runtime::spawn( |
| 1019 | async move { launcher.refresh_backgrounds(&cache, wanted).await }, |
| 1020 | ); |
| 1021 | cx.spawn(async move |this, cx| { |
| 1022 | let catalog = receiver.await.ok().flatten(); |
| 1023 | this.update(cx, |state, cx| { |
| 1024 | state.call_backgrounds.refreshing = false; |
| 1025 | if let Some(catalog) = catalog { |
| 1026 | state.call_backgrounds.images = catalog; |
| 1027 | } |
| 1028 | cx.notify(); |
| 1029 | }) |
| 1030 | .ok(); |
| 1031 | }) |
| 1032 | .detach(); |
| 1033 | } |
| 1034 | |
| 1035 | pub fn add_call_background(&mut self, cx: &mut Context<Self>) { |
| 1036 | let receiver = cx.prompt_for_paths(PathPromptOptions { |
| 1037 | files: true, |
| 1038 | directories: false, |
| 1039 | multiple: false, |
| 1040 | prompt: None, |
| 1041 | }); |
| 1042 | cx.spawn(async move |this, cx| { |
| 1043 | let Some(path) = receiver |
| 1044 | .await |
| 1045 | .ok() |
| 1046 | .and_then(Result::ok) |
| 1047 | .flatten() |
| 1048 | .and_then(|paths| paths.into_iter().next()) |
| 1049 | else { |
| 1050 | return; |
| 1051 | }; |
| 1052 | this.update(cx, |state, cx| { |
| 1053 | if !is_image_file(&path) { |
| 1054 | state.raise_notice("Pick a JPG or PNG picture".to_owned(), None, cx); |
| 1055 | return; |
| 1056 | } |
| 1057 | state.call_backgrounds.add_custom(path.clone()); |
| 1058 | save_custom_backgrounds(&state.store, &state.call_backgrounds.customs); |
| 1059 | state.set_call_background(BackgroundPick::Custom(path), cx); |
| 1060 | }) |
| 1061 | .ok(); |
| 1062 | }) |
| 1063 | .detach(); |
| 1064 | } |
| 1065 | |
| 1066 | pub fn toggle_stage_fullscreen(&mut self, cx: &mut Context<Self>) { |
| 1067 | let Some(call) = self |
| 1068 | .call |
| 1069 | .as_mut() |
| 1070 | .filter(|call| call.model.screen_sharer.is_some()) |
| 1071 | else { |
| 1072 | return; |
| 1073 | }; |
| 1074 | call.stage_fullscreen = !call.stage_fullscreen; |
| 1075 | cx.emit(AppEvent::Call); |
| 1076 | cx.notify(); |
| 1077 | } |
| 1078 | |
| 1079 | pub fn leave_stage_fullscreen(&mut self, cx: &mut Context<Self>) { |
| 1080 | let Some(call) = self.call.as_mut().filter(|call| call.stage_fullscreen) else { |
| 1081 | return; |
| 1082 | }; |
| 1083 | call.stage_fullscreen = false; |
| 1084 | cx.emit(AppEvent::Call); |
| 1085 | cx.notify(); |
| 1086 | } |
| 1087 | |
| 1088 | pub fn stage_fullscreen(&self) -> bool { |
| 1089 | self.call |
| 1090 | .as_ref() |
| 1091 | .is_some_and(|call| call.stage_fullscreen && call.model.screen_sharer.is_some()) |
| 1092 | } |
| 1093 | |
| 1094 | pub fn viewing_call(&self) -> bool { |
| 1095 | self.call.as_ref().is_some_and(|call| call.viewing) |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | impl AppState { |
| 1100 | pub fn on_engine_event(&mut self, event: EngineEvent, cx: &mut Context<Self>) { |
| 1101 | match event { |
| 1102 | EngineEvent::Incoming(ring) => self.push_ring(ring, false, cx), |
| 1103 | EngineEvent::RingEnded { ring_id, kind, .. } => { |
| 1104 | self.signal_ring(ring_id, RingSignal::Remote(kind), cx); |
| 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | fn push_ring(&mut self, ring: calling::IncomingRing, demo: bool, cx: &mut Context<Self>) { |
| 1110 | let caller_user_id = ring |
| 1111 | .caller |
| 1112 | .mri |
| 1113 | .strip_prefix(ORGID_PREFIX) |
| 1114 | .map(str::to_owned); |
| 1115 | self.rings.push(ring, demo, Instant::now()); |
| 1116 | if let Some(user_id) = caller_user_id { |
| 1117 | self.request_avatars(vec![user_id], cx); |
| 1118 | } |
| 1119 | cx.emit(AppEvent::Ring); |
| 1120 | cx.notify(); |
| 1121 | } |
| 1122 | |
| 1123 | pub fn demo_incoming_ring(&mut self, cx: &mut Context<Self>) { |
| 1124 | self.push_ring(demo_ring(), true, cx); |
| 1125 | } |
| 1126 | |
| 1127 | pub fn demo_incoming_video_ring(&mut self, cx: &mut Context<Self>) { |
| 1128 | self.push_ring(demo_video_ring(), true, cx); |
| 1129 | } |
| 1130 | |
| 1131 | pub fn start_demo_scene(&mut self, scene: DemoScene, cx: &mut Context<Self>) { |
| 1132 | if self.call.is_some() { |
| 1133 | return; |
| 1134 | } |
| 1135 | if let Some(cause) = scene.end_cause() { |
| 1136 | self.demo_call_end(cause, cx); |
| 1137 | return; |
| 1138 | } |
| 1139 | let (script, model, conversation_id) = if scene.is_one_to_one() { |
| 1140 | ( |
| 1141 | DemoCall::People(vec![demo_caller()]), |
| 1142 | CallModel::people("Mara Lindqvist", &[demo_caller()]), |
| 1143 | "demo-chat-mara", |
| 1144 | ) |
| 1145 | } else { |
| 1146 | let script = DemoCall::Meeting { |
| 1147 | guests: demo_guests(scene.guests().unwrap_or(DEMO_SMALL_MEETING)), |
| 1148 | lobby: false, |
| 1149 | organizer: true, |
| 1150 | }; |
| 1151 | ( |
| 1152 | script, |
| 1153 | CallModel::meeting("Standup", true), |
| 1154 | "demo-chat-meeting-standup", |
| 1155 | ) |
| 1156 | }; |
| 1157 | let handle = start_demo_scene_call(script, scene); |
| 1158 | self.begin_call(handle, model, Some(conversation_id.to_owned()), cx); |
| 1159 | if let Some(call) = self.call.as_mut().filter(|_| !scene.is_one_to_one()) { |
| 1160 | call.meeting_target = Some(calling::MeetingTarget { |
| 1161 | thread_id: conversation_id.to_owned(), |
| 1162 | tenant_id: "demo-tenant".to_owned(), |
| 1163 | organizer_id: "demo-me".to_owned(), |
| 1164 | meeting_data: None, |
| 1165 | }); |
| 1166 | } |
| 1167 | if scene.minimized() { |
| 1168 | self.show_call(false, cx); |
| 1169 | } |
| 1170 | if let Some(call) = self.call.as_mut().filter(|_| scene == DemoScene::Blocked) { |
| 1171 | call.model.recording_policy.call_recording = false; |
| 1172 | call.model.recording_policy.call_transcription = false; |
| 1173 | } |
| 1174 | if scene == DemoScene::Gallery { |
| 1175 | self.queue_demo_bubbles(conversation_id, cx); |
| 1176 | } |
| 1177 | if scene == DemoScene::Consult { |
| 1178 | if let Some(call) = self.call.as_mut() { |
| 1179 | call.model.apply(CallUpdate::State(CallState::Connected { |
| 1180 | since: Instant::now(), |
| 1181 | })); |
| 1182 | } |
| 1183 | self.start_consult(demo_consult_target(), cx); |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | fn signal_ring(&mut self, ring_id: u64, signal: RingSignal, cx: &mut Context<Self>) { |
| 1188 | if let Some(outcome) = self.rings.signal(ring_id, signal, Instant::now()) { |
| 1189 | self.finish_ring(ring_id, outcome, cx); |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | fn finish_ring(&mut self, ring_id: u64, outcome: RingOutcome, cx: &mut Context<Self>) { |
| 1194 | if let RingOutcome::Missed(missed) = outcome { |
| 1195 | if let Some(launcher) = &self.call_launcher { |
| 1196 | launcher.drop_ring(ring_id); |
| 1197 | } |
| 1198 | cx.emit(AppEvent::MissedCall(missed)); |
| 1199 | } |
| 1200 | cx.emit(AppEvent::Ring); |
| 1201 | cx.notify(); |
| 1202 | } |
| 1203 | |
| 1204 | pub fn tick_rings(&mut self, cx: &mut Context<Self>) { |
| 1205 | if self.rings.is_empty() { |
| 1206 | return; |
| 1207 | } |
| 1208 | for (ring_id, outcome) in self.rings.tick(Instant::now()) { |
| 1209 | self.finish_ring(ring_id, outcome, cx); |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | pub fn accept_ringing_call(&mut self, mode: AcceptMode, cx: &mut Context<Self>) { |
| 1214 | if let Some(ring_id) = self.rings.first_ringing_id() { |
| 1215 | self.accept_ring(ring_id, mode, cx); |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | pub fn decline_ringing_call(&mut self, cx: &mut Context<Self>) { |
| 1220 | if let Some(ring_id) = self.rings.first_ringing_id() { |
| 1221 | self.decline_ring(ring_id, cx); |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | pub fn accept_ring(&mut self, ring_id: u64, mode: AcceptMode, cx: &mut Context<Self>) { |
| 1226 | let Some(entry) = self.rings.get(ring_id).cloned() else { |
| 1227 | return; |
| 1228 | }; |
| 1229 | if self.call.is_some() { |
| 1230 | self.leave_call(cx); |
| 1231 | } |
| 1232 | self.signal_ring(ring_id, RingSignal::Accept, cx); |
| 1233 | let conversation_id = entry.ring.thread_id.clone(); |
| 1234 | let title = conversation_id |
| 1235 | .as_deref() |
| 1236 | .and_then(|id| self.sidebar.chats.iter().find(|chat| chat.id == id)) |
| 1237 | .filter(|_| entry.ring.is_group) |
| 1238 | .map(chat_title) |
| 1239 | .unwrap_or_else(|| entry.caller_name().to_owned()); |
| 1240 | let model = CallModel::incoming(&title, &entry.ring.caller.mri, entry.caller_name()); |
| 1241 | if entry.demo { |
| 1242 | let handle = start_demo_call(DemoCall::Incoming(demo_caller())); |
| 1243 | self.begin_call(handle, model, conversation_id, cx); |
| 1244 | if mode == AcceptMode::Video { |
| 1245 | self.send_call_command(CallCommand::SetCamera(true)); |
| 1246 | } |
| 1247 | return; |
| 1248 | } |
| 1249 | let Some(launcher) = self.call_launcher.clone() else { |
| 1250 | self.raise_notice(ANSWER_FAILED_NOTICE.to_owned(), None, cx); |
| 1251 | return; |
| 1252 | }; |
| 1253 | let receiver = |
| 1254 | crate::runtime::spawn(async move { launcher.accept_ring(ring_id, mode).await }); |
| 1255 | cx.spawn(async move |this, cx| { |
| 1256 | let handle = receiver.await.ok().flatten(); |
| 1257 | this.update(cx, |state, cx| match handle { |
| 1258 | Some(handle) => state.begin_call(handle, model, conversation_id, cx), |
| 1259 | None => state.raise_notice(ANSWER_FAILED_NOTICE.to_owned(), None, cx), |
| 1260 | }) |
| 1261 | .ok(); |
| 1262 | }) |
| 1263 | .detach(); |
| 1264 | } |
| 1265 | |
| 1266 | pub fn decline_ring(&mut self, ring_id: u64, cx: &mut Context<Self>) { |
| 1267 | let Some(entry) = self.rings.get(ring_id) else { |
| 1268 | return; |
| 1269 | }; |
| 1270 | let demo = entry.demo; |
| 1271 | if !demo && let Some(launcher) = &self.call_launcher { |
| 1272 | launcher.decline_ring(ring_id); |
| 1273 | } |
| 1274 | self.signal_ring(ring_id, RingSignal::Decline, cx); |
| 1275 | } |
| 1276 | |
| 1277 | pub fn conversation_of_missed_call(&self, missed: &MissedCall) -> Option<String> { |
| 1278 | if let Some(thread_id) = missed |
| 1279 | .thread_id |
| 1280 | .as_ref() |
| 1281 | .filter(|id| self.sidebar.chats.iter().any(|chat| &chat.id == *id)) |
| 1282 | { |
| 1283 | return Some(thread_id.clone()); |
| 1284 | } |
| 1285 | let user_id = missed.caller_mri.strip_prefix(ORGID_PREFIX)?; |
| 1286 | self.sidebar |
| 1287 | .chats |
| 1288 | .iter() |
| 1289 | .find(|chat| { |
| 1290 | crate::data::is_one_on_one(chat) |
| 1291 | && chat |
| 1292 | .members |
| 1293 | .iter() |
| 1294 | .any(|member| member.user_id.as_deref() == Some(user_id)) |
| 1295 | }) |
| 1296 | .map(|chat| chat.id.clone()) |
| 1297 | } |
| 1298 | } |
| 1299 | |
| 1300 | impl AppState { |
| 1301 | pub fn running_meeting(&self, conversation_id: &str) -> Option<&LiveMeeting> { |
| 1302 | self.live_meetings |
| 1303 | .get(conversation_id) |
| 1304 | .filter(|meeting| meeting.is_running(now_unix()) && meeting.target().is_some()) |
| 1305 | } |
| 1306 | |
| 1307 | pub fn demo_live_meetings(&mut self) { |
| 1308 | for conversation_id in ["demo-chat-meeting-standup", DEMO_LOBBY_MEETING] { |
| 1309 | self.live_meetings.insert( |
| 1310 | conversation_id.to_owned(), |
| 1311 | LiveMeeting { |
| 1312 | thread_id: conversation_id.to_owned(), |
| 1313 | conversation_url: None, |
| 1314 | expiration: Some(now_unix() + DEMO_LIVE_MINUTES * 60), |
| 1315 | organizer_id: Some("demo-jonas".to_owned()), |
| 1316 | tenant_id: Some("demo-tenant".to_owned()), |
| 1317 | meeting_code: None, |
| 1318 | passcode: None, |
| 1319 | }, |
| 1320 | ); |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | pub fn watches_live_meeting(&self, conversation_id: &str) -> bool { |
| 1325 | let meeting_chat = |
| 1326 | self.sidebar.chats.iter().any(|chat| { |
| 1327 | chat.id == conversation_id && chat.kind.eq_ignore_ascii_case(MEETING_KIND) |
| 1328 | }); |
| 1329 | meeting_chat |
| 1330 | || matches!( |
| 1331 | selection_for(&self.sidebar, conversation_id), |
| 1332 | Some(Selection::Channel(_)) |
| 1333 | ) |
| 1334 | } |
| 1335 | |
| 1336 | pub fn refresh_live_meeting(&mut self, conversation_id: &str, cx: &mut Context<Self>) { |
| 1337 | if self.watches_live_meeting(conversation_id) { |
| 1338 | self.fetch_live_meeting(conversation_id, cx); |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | pub fn fetch_live_meeting(&mut self, conversation_id: &str, cx: &mut Context<Self>) { |
| 1343 | if self.mode.demo { |
| 1344 | return; |
| 1345 | } |
| 1346 | let Some(launcher) = self.call_launcher.clone() else { |
| 1347 | return; |
| 1348 | }; |
| 1349 | if !self.live_refreshing.insert(conversation_id.to_owned()) { |
| 1350 | return; |
| 1351 | } |
| 1352 | let thread_id = conversation_id.to_owned(); |
| 1353 | let receiver = |
| 1354 | crate::runtime::spawn(async move { launcher.live_meeting(&thread_id).await }); |
| 1355 | let conversation_id = conversation_id.to_owned(); |
| 1356 | cx.spawn(async move |this, cx| { |
| 1357 | let meeting = receiver.await.ok().flatten(); |
| 1358 | this.update(cx, |state, cx| { |
| 1359 | state.apply_live_meeting(conversation_id, meeting, cx) |
| 1360 | }) |
| 1361 | .ok(); |
| 1362 | }) |
| 1363 | .detach(); |
| 1364 | } |
| 1365 | |
| 1366 | pub fn apply_live_meeting( |
| 1367 | &mut self, |
| 1368 | conversation_id: String, |
| 1369 | meeting: Option<LiveMeeting>, |
| 1370 | cx: &mut Context<Self>, |
| 1371 | ) { |
| 1372 | self.live_refreshing.remove(&conversation_id); |
| 1373 | let changed = match meeting { |
| 1374 | Some(meeting) => { |
| 1375 | self.live_meetings |
| 1376 | .insert(conversation_id.clone(), meeting.clone()) |
| 1377 | != Some(meeting) |
| 1378 | } |
| 1379 | None => self.live_meetings.remove(&conversation_id).is_some(), |
| 1380 | }; |
| 1381 | if changed { |
| 1382 | cx.emit(AppEvent::LiveMeeting); |
| 1383 | cx.notify(); |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | pub fn on_thread_changed(&mut self, conversation_id: &str, cx: &mut Context<Self>) { |
| 1388 | self.refresh_live_meeting(conversation_id, cx); |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | #[cfg(test)] |
| 1393 | mod tests { |
| 1394 | use std::sync::Arc; |
| 1395 | use std::time::{Duration, Instant}; |
| 1396 | |
| 1397 | use std::path::PathBuf; |
| 1398 | |
| 1399 | use calling::{ |
| 1400 | BackgroundChoice, CallCommand, CallControl, CallState, CallUpdate, CameraEffects, |
| 1401 | DeviceChoice, EndKind, EndReason, EngineEvent, HoldState, Reaction, RecordingKind, |
| 1402 | StopScope, call_channel, |
| 1403 | }; |
| 1404 | use gpui_kit::{AppContext as _, Entity, TestAppContext}; |
| 1405 | use store::{ChatRecord, MemberRecord, Store}; |
| 1406 | |
| 1407 | use super::{ActiveCall, CallModel, load_camera, load_camera_effects, load_input, load_output}; |
| 1408 | use crate::app_state::{AppEvent, AppState, Mode, Selection}; |
| 1409 | use crate::call::TransferCandidate; |
| 1410 | use crate::call::background::BackgroundPick; |
| 1411 | use crate::call::{CaptionPosition, CaptionSize, RecordAction, ViewSettings}; |
| 1412 | use crate::call::demo::demo_ring; |
| 1413 | use chatsvc::sounds::CallTone; |
| 1414 | use crate::call::features::room_closed_move; |
| 1415 | use crate::call::model::BreakoutState; |
| 1416 | use crate::data::Person; |
| 1417 | |
| 1418 | fn app_with_call(cx: &mut TestAppContext) -> Entity<AppState> { |
| 1419 | cx.update(gpui_kit::init); |
| 1420 | let store = Arc::new(Store::open_in_memory().unwrap()); |
| 1421 | let app = cx.update(|cx| cx.new(|_| AppState::new(store, Mode::default()))); |
| 1422 | let (handle, _control) = call_channel(); |
| 1423 | cx.update(|cx| { |
| 1424 | app.update(cx, |state, _| { |
| 1425 | state.call = Some(ActiveCall::new( |
| 1426 | 7, |
| 1427 | CallModel::test(), |
| 1428 | handle.commands, |
| 1429 | None, |
| 1430 | handle.video, |
| 1431 | )); |
| 1432 | }) |
| 1433 | }); |
| 1434 | app |
| 1435 | } |
| 1436 | |
| 1437 | fn app_with_commands( |
| 1438 | cx: &mut TestAppContext, |
| 1439 | model: CallModel, |
| 1440 | conversation_id: Option<&str>, |
| 1441 | ) -> (Entity<AppState>, CallControl) { |
| 1442 | cx.update(gpui_kit::init); |
| 1443 | let store = Arc::new(Store::open_in_memory().unwrap()); |
| 1444 | let app = cx.update(|cx| cx.new(|_| AppState::new(store, Mode::default()))); |
| 1445 | let (handle, control) = call_channel(); |
| 1446 | let conversation_id = conversation_id.map(str::to_owned); |
| 1447 | cx.update(|cx| { |
| 1448 | app.update(cx, |state, _| { |
| 1449 | state.call = Some(ActiveCall::new( |
| 1450 | 7, |
| 1451 | model, |
| 1452 | handle.commands, |
| 1453 | conversation_id, |
| 1454 | handle.video, |
| 1455 | )); |
| 1456 | }) |
| 1457 | }); |
| 1458 | (app, control) |
| 1459 | } |
| 1460 | |
| 1461 | fn live_meeting(can_end: bool) -> CallModel { |
| 1462 | let mut model = CallModel::meeting("Standup", can_end); |
| 1463 | model.apply(CallUpdate::State(CallState::Connected { |
| 1464 | since: Instant::now(), |
| 1465 | })); |
| 1466 | model.apply(CallUpdate::OwnIdentity { |
| 1467 | mri: "8:orgid:me".into(), |
| 1468 | }); |
| 1469 | model |
| 1470 | } |
| 1471 | |
| 1472 | #[gpui_kit::test] |
| 1473 | fn high_rate_updates_do_not_emit_call_events(cx: &mut TestAppContext) { |
| 1474 | let app = app_with_call(cx); |
| 1475 | let emitted = Arc::new(std::sync::atomic::AtomicUsize::new(0)); |
| 1476 | let counter = emitted.clone(); |
| 1477 | cx.update(|cx| { |
| 1478 | cx.subscribe(&app, move |_, event: &AppEvent, _| { |
| 1479 | if matches!(event, AppEvent::Call) { |
| 1480 | counter.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| 1481 | } |
| 1482 | }) |
| 1483 | .detach(); |
| 1484 | app.update(cx, |state, cx| { |
| 1485 | state.apply_call_update(7, CallUpdate::VideoReady, cx); |
| 1486 | state.apply_call_update( |
| 1487 | 7, |
| 1488 | CallUpdate::Levels { |
| 1489 | local: 0.5, |
| 1490 | remote: 0.5, |
| 1491 | }, |
| 1492 | cx, |
| 1493 | ); |
| 1494 | state.apply_call_update( |
| 1495 | 7, |
| 1496 | CallUpdate::Stats { |
| 1497 | inbound_packets: 1, |
| 1498 | outbound_packets: 1, |
| 1499 | }, |
| 1500 | cx, |
| 1501 | ); |
| 1502 | }); |
| 1503 | }); |
| 1504 | assert_eq!(emitted.load(std::sync::atomic::Ordering::SeqCst), 0); |
| 1505 | assert!(cx.update(|cx| app.read(cx).call.as_ref().unwrap().model.remote_speaking)); |
| 1506 | cx.update(|cx| { |
| 1507 | app.update(cx, |state, cx| { |
| 1508 | state.apply_call_update(7, CallUpdate::Muted(true), cx) |
| 1509 | }) |
| 1510 | }); |
| 1511 | assert_eq!(emitted.load(std::sync::atomic::Ordering::SeqCst), 1); |
| 1512 | } |
| 1513 | |
| 1514 | #[gpui_kit::test] |
| 1515 | fn the_computer_sound_switch_is_remembered_and_sent_to_the_call(cx: &mut TestAppContext) { |
| 1516 | let (app, mut control) = app_with_commands(cx, live_meeting(false), None); |
| 1517 | let store = cx.update(|cx| app.read(cx).store.clone()); |
| 1518 | assert!(!cx.update(|cx| app.read(cx).call_share_sound)); |
| 1519 | cx.update(|cx| app.update(cx, |state, cx| state.set_call_share_sound(true, cx))); |
| 1520 | assert_eq!( |
| 1521 | control.try_recv_command(), |
| 1522 | Some(CallCommand::SetShareSound(true)) |
| 1523 | ); |
| 1524 | let reopened = cx.update(|cx| cx.new(|_| AppState::new(store.clone(), Mode::default()))); |
| 1525 | assert!(cx.update(|cx| reopened.read(cx).call_share_sound)); |
| 1526 | cx.update(|cx| app.update(cx, |state, cx| state.set_call_share_sound(false, cx))); |
| 1527 | let reopened = cx.update(|cx| cx.new(|_| AppState::new(store.clone(), Mode::default()))); |
| 1528 | assert!(!cx.update(|cx| reopened.read(cx).call_share_sound)); |
| 1529 | } |
| 1530 | |
| 1531 | #[gpui_kit::test] |
| 1532 | fn in_call_device_picks_are_saved_including_system_default(cx: &mut TestAppContext) { |
| 1533 | let (app, mut control) = app_with_commands(cx, live_meeting(false), None); |
| 1534 | let store = cx.update(|cx| app.read(cx).store.clone()); |
| 1535 | assert_eq!(load_input(&store), DeviceChoice::SystemDefault); |
| 1536 | cx.update(|cx| { |
| 1537 | app.update(cx, |state, cx| { |
| 1538 | state.select_call_input(DeviceChoice::Device("headset-mic".into()), cx); |
| 1539 | state.select_call_output(DeviceChoice::Device("headset".into()), cx); |
| 1540 | }) |
| 1541 | }); |
| 1542 | assert_eq!(load_input(&store), DeviceChoice::Device("headset-mic".into())); |
| 1543 | assert_eq!(load_output(&store), DeviceChoice::Device("headset".into())); |
| 1544 | assert_eq!( |
| 1545 | control.try_recv_command(), |
| 1546 | Some(CallCommand::SelectInput(DeviceChoice::Device("headset-mic".into()))) |
| 1547 | ); |
| 1548 | cx.update(|cx| { |
| 1549 | app.update(cx, |state, cx| { |
| 1550 | state.select_call_input(DeviceChoice::SystemDefault, cx) |
| 1551 | }) |
| 1552 | }); |
| 1553 | assert_eq!(load_input(&store), DeviceChoice::SystemDefault); |
| 1554 | let reopened = cx.update(|cx| cx.new(|_| AppState::new(store.clone(), Mode::default()))); |
| 1555 | assert_eq!( |
| 1556 | cx.update(|cx| reopened.read(cx).call_output.clone()), |
| 1557 | DeviceChoice::Device("headset".into()) |
| 1558 | ); |
| 1559 | } |
| 1560 | |
| 1561 | #[gpui_kit::test] |
| 1562 | fn every_call_starts_with_the_saved_devices_even_when_they_are_not_present( |
| 1563 | cx: &mut TestAppContext, |
| 1564 | ) { |
| 1565 | cx.update(gpui_kit::init); |
| 1566 | let store = Arc::new(Store::open_in_memory().unwrap()); |
| 1567 | let app = cx.update(|cx| cx.new(|_| AppState::new(store.clone(), Mode::default()))); |
| 1568 | cx.update(|cx| { |
| 1569 | app.update(cx, |state, cx| { |
| 1570 | state.select_call_input(DeviceChoice::Device("unplugged-mic".into()), cx); |
| 1571 | state.select_call_output(DeviceChoice::Device("headset".into()), cx); |
| 1572 | }) |
| 1573 | }); |
| 1574 | let (handle, mut control) = call_channel(); |
| 1575 | cx.update(|cx| { |
| 1576 | app.update(cx, |state, cx| { |
| 1577 | state.begin_call(handle, CallModel::test(), None, cx) |
| 1578 | }) |
| 1579 | }); |
| 1580 | let mut commands = Vec::new(); |
| 1581 | while let Some(command) = control.try_recv_command() { |
| 1582 | commands.push(command); |
| 1583 | } |
| 1584 | assert!(commands.contains(&CallCommand::SelectInput(DeviceChoice::Device( |
| 1585 | "unplugged-mic".into() |
| 1586 | )))); |
| 1587 | assert!(commands.contains(&CallCommand::SelectOutput(DeviceChoice::Device( |
| 1588 | "headset".into() |
| 1589 | )))); |
| 1590 | assert_eq!( |
| 1591 | load_input(&store), |
| 1592 | DeviceChoice::Device("unplugged-mic".into()) |
| 1593 | ); |
| 1594 | } |
| 1595 | |
| 1596 | #[gpui_kit::test] |
| 1597 | fn the_camera_pick_is_remembered_and_the_next_call_starts_with_it(cx: &mut TestAppContext) { |
| 1598 | let (app, _control) = app_with_commands(cx, live_meeting(false), None); |
| 1599 | let store = cx.update(|cx| app.read(cx).store.clone()); |
| 1600 | assert_eq!(load_camera(&store), DeviceChoice::SystemDefault); |
| 1601 | cx.update(|cx| { |
| 1602 | app.update(cx, |state, cx| { |
| 1603 | state.select_call_camera(DeviceChoice::Device("cam-2".into()), cx) |
| 1604 | }) |
| 1605 | }); |
| 1606 | assert_eq!(load_camera(&store), DeviceChoice::Device("cam-2".into())); |
| 1607 | let reopened = cx.update(|cx| cx.new(|_| AppState::new(store.clone(), Mode::default()))); |
| 1608 | assert_eq!( |
| 1609 | cx.update(|cx| reopened.read(cx).call_camera.clone()), |
| 1610 | DeviceChoice::Device("cam-2".into()) |
| 1611 | ); |
| 1612 | cx.update(|cx| { |
| 1613 | app.update(cx, |state, cx| { |
| 1614 | state.select_call_camera(DeviceChoice::SystemDefault, cx) |
| 1615 | }) |
| 1616 | }); |
| 1617 | assert_eq!(load_camera(&store), DeviceChoice::SystemDefault); |
| 1618 | } |
| 1619 | |
| 1620 | #[gpui_kit::test] |
| 1621 | fn the_camera_effects_are_remembered_and_sent_to_the_call(cx: &mut TestAppContext) { |
| 1622 | let (app, mut control) = app_with_commands(cx, live_meeting(false), None); |
| 1623 | let store = cx.update(|cx| app.read(cx).store.clone()); |
| 1624 | assert_eq!(load_camera_effects(&store), CameraEffects::default()); |
| 1625 | let effects = CameraEffects { |
| 1626 | mirror: false, |
| 1627 | auto_framing: true, |
| 1628 | soft_focus: true, |
| 1629 | soft_focus_strength: 75, |
| 1630 | ..CameraEffects::default() |
| 1631 | }; |
| 1632 | cx.update(|cx| app.update(cx, |state, cx| state.set_call_effects(effects, cx))); |
| 1633 | assert_eq!( |
| 1634 | control.try_recv_command(), |
| 1635 | Some(CallCommand::SetCameraEffects(effects)) |
| 1636 | ); |
| 1637 | assert_eq!(load_camera_effects(&store), effects); |
| 1638 | let reopened = cx.update(|cx| cx.new(|_| AppState::new(store.clone(), Mode::default()))); |
| 1639 | assert_eq!(cx.update(|cx| reopened.read(cx).call_effects), effects); |
| 1640 | } |
| 1641 | |
| 1642 | #[gpui_kit::test] |
| 1643 | fn hands_and_reactions_become_call_commands_and_lowering_needs_the_organizer( |
| 1644 | cx: &mut TestAppContext, |
| 1645 | ) { |
| 1646 | let (app, mut control) = app_with_commands(cx, live_meeting(false), None); |
| 1647 | cx.update(|cx| { |
| 1648 | app.update(cx, |state, cx| { |
| 1649 | state.toggle_call_hand(cx); |
| 1650 | state.send_call_reaction(Reaction::Heart, cx); |
| 1651 | state.lower_call_hand("8:orgid:a".into(), cx); |
| 1652 | state.lower_all_call_hands(cx); |
| 1653 | }) |
| 1654 | }); |
| 1655 | assert_eq!(control.try_recv_command(), Some(CallCommand::SetHand(true))); |
| 1656 | assert_eq!( |
| 1657 | control.try_recv_command(), |
| 1658 | Some(CallCommand::SendReaction(Reaction::Heart)) |
| 1659 | ); |
| 1660 | assert_eq!(control.try_recv_command(), None); |
| 1661 | let (organizer, mut organizer_control) = app_with_commands(cx, live_meeting(true), None); |
| 1662 | cx.update(|cx| { |
| 1663 | organizer.update(cx, |state, cx| { |
| 1664 | state.apply_call_update( |
| 1665 | 7, |
| 1666 | CallUpdate::Roster(vec![calling::RosterEntry { |
| 1667 | mri: "8:orgid:a".into(), |
| 1668 | display_name: "Ana".into(), |
| 1669 | muted: false, |
| 1670 | in_lobby: false, |
| 1671 | has_video: false, |
| 1672 | sharing: false, |
| 1673 | hand: Some(calling::RaisedHand { |
| 1674 | state_id: "s".into(), |
| 1675 | rank: 1, |
| 1676 | }), |
| 1677 | spotlight: None, |
| 1678 | organizer: false, |
| 1679 | ..Default::default() |
| 1680 | }]), |
| 1681 | cx, |
| 1682 | ); |
| 1683 | state.lower_call_hand("8:orgid:a".into(), cx); |
| 1684 | state.lower_all_call_hands(cx); |
| 1685 | }) |
| 1686 | }); |
| 1687 | assert_eq!( |
| 1688 | organizer_control.try_recv_command(), |
| 1689 | Some(CallCommand::LowerHand { |
| 1690 | mri: "8:orgid:a".into() |
| 1691 | }) |
| 1692 | ); |
| 1693 | assert_eq!( |
| 1694 | organizer_control.try_recv_command(), |
| 1695 | Some(CallCommand::LowerAllHands) |
| 1696 | ); |
| 1697 | } |
| 1698 | |
| 1699 | fn guest(mri: &str, name: &str, in_lobby: bool, spotlit: bool) -> calling::RosterEntry { |
| 1700 | calling::RosterEntry { |
| 1701 | mri: mri.into(), |
| 1702 | display_name: name.into(), |
| 1703 | muted: false, |
| 1704 | in_lobby, |
| 1705 | has_video: false, |
| 1706 | sharing: false, |
| 1707 | hand: None, |
| 1708 | spotlight: spotlit.then(|| calling::Spotlight { |
| 1709 | state_id: "sp".into(), |
| 1710 | rank: 1, |
| 1711 | }), |
| 1712 | organizer: false, |
| 1713 | ..Default::default() |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | #[gpui_kit::test] |
| 1718 | fn organizer_controls_become_commands_and_attendees_send_nothing(cx: &mut TestAppContext) { |
| 1719 | let (attendee, mut attendee_control) = app_with_commands(cx, live_meeting(false), None); |
| 1720 | cx.update(|cx| { |
| 1721 | attendee.update(cx, |state, cx| { |
| 1722 | state.admit_call_guest("8:orgid:g".into(), cx); |
| 1723 | state.admit_all_call_guests(cx); |
| 1724 | state.deny_call_guest("8:orgid:g".into(), cx); |
| 1725 | state.mute_call_participant("8:orgid:a".into(), cx); |
| 1726 | state.mute_all_call(cx); |
| 1727 | state.remove_call_participant("8:orgid:a".into(), cx); |
| 1728 | state.toggle_call_spotlight("8:orgid:a".into(), cx); |
| 1729 | }) |
| 1730 | }); |
| 1731 | assert_eq!(attendee_control.try_recv_command(), None); |
| 1732 | let (organizer, mut control) = app_with_commands(cx, live_meeting(true), None); |
| 1733 | cx.update(|cx| { |
| 1734 | organizer.update(cx, |state, cx| { |
| 1735 | state.apply_call_update( |
| 1736 | 7, |
| 1737 | CallUpdate::Roster(vec![ |
| 1738 | guest("8:orgid:a", "Ana", false, false), |
| 1739 | guest("8:orgid:g", "Gast", true, false), |
| 1740 | ]), |
| 1741 | cx, |
| 1742 | ); |
| 1743 | state.admit_call_guest("8:orgid:g".into(), cx); |
| 1744 | state.admit_all_call_guests(cx); |
| 1745 | state.deny_call_guest("8:orgid:g".into(), cx); |
| 1746 | state.mute_call_participant("8:orgid:a".into(), cx); |
| 1747 | state.mute_all_call(cx); |
| 1748 | state.remove_call_participant("8:orgid:a".into(), cx); |
| 1749 | state.toggle_call_spotlight("8:orgid:a".into(), cx); |
| 1750 | }) |
| 1751 | }); |
| 1752 | assert_eq!( |
| 1753 | control.try_recv_command(), |
| 1754 | Some(CallCommand::Admit { |
| 1755 | mri: "8:orgid:g".into() |
| 1756 | }) |
| 1757 | ); |
| 1758 | assert_eq!(control.try_recv_command(), Some(CallCommand::AdmitAll)); |
| 1759 | assert_eq!( |
| 1760 | control.try_recv_command(), |
| 1761 | Some(CallCommand::Deny { |
| 1762 | mri: "8:orgid:g".into() |
| 1763 | }) |
| 1764 | ); |
| 1765 | assert_eq!( |
| 1766 | control.try_recv_command(), |
| 1767 | Some(CallCommand::MuteParticipant { |
| 1768 | mri: "8:orgid:a".into() |
| 1769 | }) |
| 1770 | ); |
| 1771 | assert_eq!(control.try_recv_command(), Some(CallCommand::MuteAll)); |
| 1772 | assert_eq!( |
| 1773 | control.try_recv_command(), |
| 1774 | Some(CallCommand::RemoveParticipant { |
| 1775 | mri: "8:orgid:a".into() |
| 1776 | }) |
| 1777 | ); |
| 1778 | assert_eq!( |
| 1779 | control.try_recv_command(), |
| 1780 | Some(CallCommand::Spotlight { |
| 1781 | mri: "8:orgid:a".into() |
| 1782 | }) |
| 1783 | ); |
| 1784 | } |
| 1785 | |
| 1786 | #[gpui_kit::test] |
| 1787 | fn the_spotlight_button_stops_an_existing_spotlight_and_pinning_stays_local( |
| 1788 | cx: &mut TestAppContext, |
| 1789 | ) { |
| 1790 | let (app, mut control) = app_with_commands(cx, live_meeting(true), None); |
| 1791 | cx.update(|cx| { |
| 1792 | app.update(cx, |state, cx| { |
| 1793 | state.apply_call_update( |
| 1794 | 7, |
| 1795 | CallUpdate::Roster(vec![guest("8:orgid:a", "Ana", false, true)]), |
| 1796 | cx, |
| 1797 | ); |
| 1798 | state.toggle_call_spotlight("8:orgid:a".into(), cx); |
| 1799 | state.toggle_call_pin("8:orgid:a", cx); |
| 1800 | assert_eq!( |
| 1801 | state.call.as_ref().unwrap().model.pinned.as_deref(), |
| 1802 | Some("8:orgid:a") |
| 1803 | ); |
| 1804 | state.toggle_call_pin("8:orgid:a", cx); |
| 1805 | assert_eq!(state.call.as_ref().unwrap().model.pinned, None); |
| 1806 | }) |
| 1807 | }); |
| 1808 | assert_eq!( |
| 1809 | control.try_recv_command(), |
| 1810 | Some(CallCommand::StopSpotlight { |
| 1811 | mri: "8:orgid:a".into() |
| 1812 | }) |
| 1813 | ); |
| 1814 | assert_eq!(control.try_recv_command(), None); |
| 1815 | } |
| 1816 | |
| 1817 | #[gpui_kit::test] |
| 1818 | fn captions_toggle_between_on_and_off_and_only_in_meetings(cx: &mut TestAppContext) { |
| 1819 | let (app, mut control) = app_with_commands(cx, live_meeting(false), None); |
| 1820 | cx.update(|cx| { |
| 1821 | app.update(cx, |state, cx| { |
| 1822 | state.toggle_call_captions(cx); |
| 1823 | state.apply_call_update(7, CallUpdate::Captions(calling::CaptionState::On), cx); |
| 1824 | state.toggle_call_captions(cx); |
| 1825 | }) |
| 1826 | }); |
| 1827 | assert_eq!( |
| 1828 | control.try_recv_command(), |
| 1829 | Some(CallCommand::SetCaptions(true)) |
| 1830 | ); |
| 1831 | assert_eq!( |
| 1832 | control.try_recv_command(), |
| 1833 | Some(CallCommand::SetCaptions(false)) |
| 1834 | ); |
| 1835 | let app = app_with_call(cx); |
| 1836 | cx.update(|cx| app.update(cx, |state, cx| state.toggle_call_captions(cx))); |
| 1837 | } |
| 1838 | |
| 1839 | #[gpui_kit::test] |
| 1840 | fn the_background_choice_is_remembered_and_sent_to_the_call(cx: &mut TestAppContext) { |
| 1841 | let (app, mut control) = app_with_commands(cx, live_meeting(false), None); |
| 1842 | let store = cx.update(|cx| app.read(cx).store.clone()); |
| 1843 | assert_eq!( |
| 1844 | cx.update(|cx| app.read(cx).call_background.clone()), |
| 1845 | BackgroundPick::None |
| 1846 | ); |
| 1847 | cx.update(|cx| { |
| 1848 | app.update(cx, |state, cx| { |
| 1849 | state.set_call_background(BackgroundPick::Blur, cx) |
| 1850 | }) |
| 1851 | }); |
| 1852 | assert_eq!( |
| 1853 | control.try_recv_command(), |
| 1854 | Some(CallCommand::SetBackground(BackgroundChoice::Blur)) |
| 1855 | ); |
| 1856 | assert_eq!( |
| 1857 | cx.update(|cx| app.read(cx).call.as_ref().unwrap().model.background.clone()), |
| 1858 | BackgroundPick::Blur |
| 1859 | ); |
| 1860 | let reopened = cx.update(|cx| cx.new(|_| AppState::new(store.clone(), Mode::default()))); |
| 1861 | assert_eq!( |
| 1862 | cx.update(|cx| reopened.read(cx).call_background.clone()), |
| 1863 | BackgroundPick::Blur |
| 1864 | ); |
| 1865 | let picture = PathBuf::from("/pictures/wall.jpg"); |
| 1866 | cx.update(|cx| { |
| 1867 | app.update(cx, |state, cx| { |
| 1868 | state.set_call_background(BackgroundPick::Custom(picture.clone()), cx) |
| 1869 | }) |
| 1870 | }); |
| 1871 | assert_eq!( |
| 1872 | control.try_recv_command(), |
| 1873 | Some(CallCommand::SetBackground(BackgroundChoice::Image( |
| 1874 | picture.clone() |
| 1875 | ))) |
| 1876 | ); |
| 1877 | let reopened = cx.update(|cx| cx.new(|_| AppState::new(store.clone(), Mode::default()))); |
| 1878 | assert_eq!( |
| 1879 | cx.update(|cx| reopened.read(cx).call_background.clone()), |
| 1880 | BackgroundPick::Custom(picture) |
| 1881 | ); |
| 1882 | cx.update(|cx| { |
| 1883 | app.update(cx, |state, cx| { |
| 1884 | state.set_call_background(BackgroundPick::None, cx) |
| 1885 | }) |
| 1886 | }); |
| 1887 | assert_eq!( |
| 1888 | control.try_recv_command(), |
| 1889 | Some(CallCommand::SetBackground(BackgroundChoice::None)) |
| 1890 | ); |
| 1891 | } |
| 1892 | |
| 1893 | #[gpui_kit::test] |
| 1894 | fn a_default_image_that_is_not_downloaded_yet_sends_nothing(cx: &mut TestAppContext) { |
| 1895 | let (app, mut control) = app_with_commands(cx, live_meeting(false), None); |
| 1896 | cx.update(|cx| { |
| 1897 | app.update(cx, |state, cx| { |
| 1898 | state.set_call_background(BackgroundPick::Default("office_01".into()), cx) |
| 1899 | }) |
| 1900 | }); |
| 1901 | assert_eq!(control.try_recv_command(), None); |
| 1902 | } |
| 1903 | |
| 1904 | #[gpui_kit::test] |
| 1905 | fn attendees_cannot_start_a_recording_and_the_notice_needs_a_consent_request( |
| 1906 | cx: &mut TestAppContext, |
| 1907 | ) { |
| 1908 | let mut attendee_model = live_meeting(false); |
| 1909 | attendee_model.own_role = Some(calling::MeetingRole::Attendee); |
| 1910 | let (attendee, mut attendee_control) = app_with_commands(cx, attendee_model, None); |
| 1911 | cx.update(|cx| { |
| 1912 | attendee.update(cx, |state, cx| { |
| 1913 | state.run_call_record_action(RecordAction::Start(RecordingKind::Video), cx); |
| 1914 | state.accept_recording_notice(cx); |
| 1915 | }) |
| 1916 | }); |
| 1917 | assert_eq!(attendee_control.try_recv_command(), None); |
| 1918 | let (organizer, mut control) = app_with_commands(cx, live_meeting(true), None); |
| 1919 | cx.update(|cx| { |
| 1920 | organizer.update(cx, |state, cx| { |
| 1921 | state.run_call_record_action(RecordAction::Start(RecordingKind::Video), cx); |
| 1922 | state.apply_call_update(7, CallUpdate::Recording(true), cx); |
| 1923 | state.run_call_record_action(RecordAction::Stop(StopScope::Both), cx); |
| 1924 | state.accept_recording_notice(cx); |
| 1925 | state.apply_call_update(7, CallUpdate::ConsentRequired(true), cx); |
| 1926 | state.accept_recording_notice(cx); |
| 1927 | }) |
| 1928 | }); |
| 1929 | assert_eq!( |
| 1930 | control.try_recv_command(), |
| 1931 | Some(CallCommand::StartRecording { |
| 1932 | kind: RecordingKind::Video, |
| 1933 | title: "Standup".into() |
| 1934 | }) |
| 1935 | ); |
| 1936 | assert_eq!( |
| 1937 | control.try_recv_command(), |
| 1938 | Some(CallCommand::StopRecording { |
| 1939 | scope: StopScope::Both |
| 1940 | }) |
| 1941 | ); |
| 1942 | assert_eq!( |
| 1943 | control.try_recv_command(), |
| 1944 | Some(CallCommand::ConsentToRecording) |
| 1945 | ); |
| 1946 | assert_eq!(control.try_recv_command(), None); |
| 1947 | } |
| 1948 | |
| 1949 | #[gpui_kit::test] |
| 1950 | fn every_record_action_becomes_its_own_command_for_the_organizer(cx: &mut TestAppContext) { |
| 1951 | let (organizer, mut control) = app_with_commands(cx, live_meeting(true), None); |
| 1952 | cx.update(|cx| { |
| 1953 | organizer.update(cx, |state, cx| { |
| 1954 | state.run_call_record_action(RecordAction::Start(RecordingKind::AudioOnly), cx); |
| 1955 | state.run_call_record_action(RecordAction::Start(RecordingKind::TranscriptOnly), cx); |
| 1956 | state.run_call_record_action(RecordAction::Stop(StopScope::RecordingOnly), cx); |
| 1957 | state.run_call_record_action(RecordAction::Stop(StopScope::TranscriptionOnly), cx); |
| 1958 | }) |
| 1959 | }); |
| 1960 | let title = "Standup".to_owned(); |
| 1961 | assert_eq!(control.try_recv_command(), Some(CallCommand::StartRecording { kind: RecordingKind::AudioOnly, title: title.clone() })); |
| 1962 | assert_eq!(control.try_recv_command(), Some(CallCommand::StartRecording { kind: RecordingKind::TranscriptOnly, title })); |
| 1963 | assert_eq!(control.try_recv_command(), Some(CallCommand::StopRecording { scope: StopScope::RecordingOnly })); |
| 1964 | assert_eq!(control.try_recv_command(), Some(CallCommand::StopRecording { scope: StopScope::TranscriptionOnly })); |
| 1965 | assert_eq!(control.try_recv_command(), None); |
| 1966 | } |
| 1967 | |
| 1968 | #[gpui_kit::test] |
| 1969 | fn the_transcript_turns_captions_on_and_excludes_the_chat_panel(cx: &mut TestAppContext) { |
| 1970 | let (app, mut control) = app_with_commands(cx, live_meeting(false), None); |
| 1971 | cx.update(|cx| { |
| 1972 | app.update(cx, |state, cx| { |
| 1973 | state.apply_call_update(7, CallUpdate::MeetingChat("19:meeting_x@thread.v2".into()), cx); |
| 1974 | state.toggle_call_chat(cx); |
| 1975 | state.show_call_transcript(cx); |
| 1976 | }) |
| 1977 | }); |
| 1978 | let (chat_open, transcript_open) = cx.update(|cx| { |
| 1979 | let call = app.read(cx).call.as_ref().unwrap(); |
| 1980 | (call.chat_open, call.transcript_open) |
| 1981 | }); |
| 1982 | assert!(!chat_open && transcript_open); |
| 1983 | assert_eq!(control.try_recv_command(), Some(CallCommand::SetCaptions(true))); |
| 1984 | cx.update(|cx| { |
| 1985 | app.update(cx, |state, cx| { |
| 1986 | state.apply_call_update(7, CallUpdate::Captions(calling::CaptionState::On), cx); |
| 1987 | state.show_call_transcript(cx); |
| 1988 | state.toggle_call_chat(cx); |
| 1989 | }) |
| 1990 | }); |
| 1991 | let (chat_open, transcript_open) = cx.update(|cx| { |
| 1992 | let call = app.read(cx).call.as_ref().unwrap(); |
| 1993 | (call.chat_open, call.transcript_open) |
| 1994 | }); |
| 1995 | assert!(chat_open && !transcript_open); |
| 1996 | assert_eq!(control.try_recv_command(), None); |
| 1997 | } |
| 1998 | |
| 1999 | #[gpui_kit::test] |
| 2000 | fn a_spoken_language_picked_while_captions_are_off_is_sent_once_they_are_on(cx: &mut TestAppContext) { |
| 2001 | let (app, mut control) = app_with_commands(cx, live_meeting(false), None); |
| 2002 | cx.update(|cx| { |
| 2003 | app.update(cx, |state, cx| { |
| 2004 | state.choose_call_caption_language("de-DE", cx); |
| 2005 | state.apply_call_update(7, CallUpdate::Captions(calling::CaptionState::Starting), cx); |
| 2006 | }) |
| 2007 | }); |
| 2008 | assert_eq!(control.try_recv_command(), Some(CallCommand::SetCaptions(true))); |
| 2009 | assert_eq!(control.try_recv_command(), None); |
| 2010 | cx.update(|cx| { |
| 2011 | app.update(cx, |state, cx| { |
| 2012 | state.apply_call_update(7, CallUpdate::Captions(calling::CaptionState::On), cx); |
| 2013 | state.choose_call_caption_language("fr-FR", cx); |
| 2014 | }) |
| 2015 | }); |
| 2016 | assert_eq!(control.try_recv_command(), Some(CallCommand::SetCaptionLanguage("de-DE".into()))); |
| 2017 | assert_eq!(control.try_recv_command(), Some(CallCommand::SetCaptionLanguage("fr-FR".into()))); |
| 2018 | assert_eq!(control.try_recv_command(), None); |
| 2019 | } |
| 2020 | |
| 2021 | #[gpui_kit::test] |
| 2022 | fn caption_size_and_position_are_stored_and_reach_the_call_model(cx: &mut TestAppContext) { |
| 2023 | let (app, _control) = app_with_commands(cx, live_meeting(false), None); |
| 2024 | cx.update(|cx| { |
| 2025 | app.update(cx, |state, cx| { |
| 2026 | state.set_call_caption_size(CaptionSize::Large, cx); |
| 2027 | state.set_call_caption_position(CaptionPosition::Top, cx); |
| 2028 | }) |
| 2029 | }); |
| 2030 | let (view, stored) = cx.update(|cx| { |
| 2031 | let state = app.read(cx); |
| 2032 | (state.call.as_ref().unwrap().model.view, ViewSettings::load(&state.store)) |
| 2033 | }); |
| 2034 | assert_eq!((view.caption_size, view.caption_position), (CaptionSize::Large, CaptionPosition::Top)); |
| 2035 | assert_eq!((stored.caption_size, stored.caption_position), (CaptionSize::Large, CaptionPosition::Top)); |
| 2036 | } |
| 2037 | |
| 2038 | fn live_one_to_one() -> CallModel { |
| 2039 | let mut model = CallModel::people("Bea", &[("8:orgid:bea".into(), "Bea".into())]); |
| 2040 | model.apply(CallUpdate::State(CallState::Connected { |
| 2041 | since: Instant::now(), |
| 2042 | })); |
| 2043 | model |
| 2044 | } |
| 2045 | |
| 2046 | #[gpui_kit::test] |
| 2047 | fn hold_and_resume_alternate_and_stop_while_the_other_side_holds(cx: &mut TestAppContext) { |
| 2048 | let (app, mut control) = app_with_commands(cx, live_one_to_one(), None); |
| 2049 | cx.update(|cx| { |
| 2050 | app.update(cx, |state, cx| { |
| 2051 | state.toggle_call_hold(cx); |
| 2052 | state.apply_call_update(7, CallUpdate::Hold(HoldState::Local), cx); |
| 2053 | state.toggle_call_hold(cx); |
| 2054 | state.apply_call_update(7, CallUpdate::Hold(HoldState::Remote), cx); |
| 2055 | state.toggle_call_hold(cx); |
| 2056 | }) |
| 2057 | }); |
| 2058 | assert_eq!(control.try_recv_command(), Some(CallCommand::Hold(true))); |
| 2059 | assert_eq!(control.try_recv_command(), Some(CallCommand::Hold(false))); |
| 2060 | assert_eq!(control.try_recv_command(), None); |
| 2061 | let (meeting, mut meeting_control) = app_with_commands(cx, live_meeting(true), None); |
| 2062 | cx.update(|cx| meeting.update(cx, |state, cx| state.toggle_call_hold(cx))); |
| 2063 | assert_eq!(meeting_control.try_recv_command(), None); |
| 2064 | } |
| 2065 | |
| 2066 | fn candidate(name: &str) -> TransferCandidate { |
| 2067 | TransferCandidate { |
| 2068 | mri: format!("8:orgid:{name}"), |
| 2069 | name: name.into(), |
| 2070 | user_id: Some(name.into()), |
| 2071 | chat_id: format!("19:{name}"), |
| 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | #[gpui_kit::test] |
| 2076 | fn a_blind_transfer_names_the_target( |
| 2077 | cx: &mut TestAppContext, |
| 2078 | ) { |
| 2079 | let (app, mut control) = app_with_commands(cx, live_one_to_one(), None); |
| 2080 | cx.update(|cx| { |
| 2081 | app.update(cx, |state, cx| { |
| 2082 | state.transfer_call_blind(candidate("ana"), cx) |
| 2083 | }) |
| 2084 | }); |
| 2085 | assert_eq!( |
| 2086 | control.try_recv_command(), |
| 2087 | Some(CallCommand::Transfer { |
| 2088 | target: calling::Callee { |
| 2089 | mri: "8:orgid:ana".into(), |
| 2090 | display_name: "ana".into() |
| 2091 | }, |
| 2092 | replaces: None |
| 2093 | }) |
| 2094 | ); |
| 2095 | } |
| 2096 | |
| 2097 | #[gpui_kit::test] |
| 2098 | fn the_transfer_list_holds_one_to_one_chats_without_the_person_on_the_call( |
| 2099 | cx: &mut TestAppContext, |
| 2100 | ) { |
| 2101 | let app = app_with_chats(cx); |
| 2102 | cx.update(|cx| { |
| 2103 | app.update(cx, |state, cx| { |
| 2104 | let names: Vec<String> = state |
| 2105 | .transfer_candidates() |
| 2106 | .into_iter() |
| 2107 | .map(|candidate| candidate.name) |
| 2108 | .collect(); |
| 2109 | assert_eq!(names, vec!["Bea".to_owned()]); |
| 2110 | let (handle, _control) = call_channel(); |
| 2111 | let mut on_the_call = |
| 2112 | CallModel::people("Bea", &[("8:orgid:bea-id".into(), "Bea".into())]); |
| 2113 | on_the_call.apply(CallUpdate::State(CallState::Connected { |
| 2114 | since: Instant::now(), |
| 2115 | })); |
| 2116 | state.call = Some(ActiveCall::new( |
| 2117 | 9, |
| 2118 | on_the_call, |
| 2119 | handle.commands, |
| 2120 | None, |
| 2121 | handle.video, |
| 2122 | )); |
| 2123 | assert!(state.transfer_candidates().is_empty()); |
| 2124 | cx.notify(); |
| 2125 | }) |
| 2126 | }); |
| 2127 | } |
| 2128 | |
| 2129 | fn room_move(returning: bool) -> calling::BreakoutMove { |
| 2130 | calling::BreakoutMove { |
| 2131 | room_name: "Room 1".into(), |
| 2132 | target: calling::MeetingTarget { |
| 2133 | thread_id: "19:meeting_room@thread.v2".into(), |
| 2134 | tenant_id: "t".into(), |
| 2135 | organizer_id: "o".into(), |
| 2136 | meeting_data: None, |
| 2137 | }, |
| 2138 | returning, |
| 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | fn main_target() -> calling::MeetingTarget { |
| 2143 | calling::MeetingTarget { |
| 2144 | thread_id: "19:meeting_main@thread.v2".into(), |
| 2145 | tenant_id: "t".into(), |
| 2146 | organizer_id: "o".into(), |
| 2147 | meeting_data: None, |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | #[gpui_kit::test] |
| 2152 | fn being_moved_to_a_room_leaves_the_call_and_remembers_the_way_back(cx: &mut TestAppContext) { |
| 2153 | let (app, mut control) = app_with_commands(cx, live_meeting(false), None); |
| 2154 | cx.update(|cx| { |
| 2155 | app.update(cx, |state, cx| { |
| 2156 | state.call.as_mut().unwrap().meeting_target = Some(main_target()); |
| 2157 | state.apply_call_update(7, CallUpdate::BreakoutMove(room_move(false)), cx); |
| 2158 | let pending = state |
| 2159 | .call |
| 2160 | .as_ref() |
| 2161 | .unwrap() |
| 2162 | .pending_move |
| 2163 | .clone() |
| 2164 | .expect("a move is pending"); |
| 2165 | assert_eq!(pending.target.thread_id, "19:meeting_room@thread.v2"); |
| 2166 | assert_eq!(pending.title, "Room 1"); |
| 2167 | let room = pending.breakout.expect("a room"); |
| 2168 | assert_eq!(room.main, Some(main_target())); |
| 2169 | assert_eq!(room.main_title, "Standup"); |
| 2170 | assert_eq!( |
| 2171 | state.notice.as_ref().map(|notice| notice.text.as_str()), |
| 2172 | Some("Moving you to Room 1") |
| 2173 | ); |
| 2174 | state.apply_call_update(7, CallUpdate::BreakoutMove(room_move(false)), cx); |
| 2175 | }) |
| 2176 | }); |
| 2177 | assert_eq!(control.try_recv_command(), Some(CallCommand::Hangup)); |
| 2178 | assert_eq!(control.try_recv_command(), None); |
| 2179 | } |
| 2180 | |
| 2181 | #[gpui_kit::test] |
| 2182 | fn the_return_button_and_a_closed_room_both_lead_back_to_the_main_meeting( |
| 2183 | cx: &mut TestAppContext, |
| 2184 | ) { |
| 2185 | let mut room = live_meeting(false); |
| 2186 | room.breakout = Some(BreakoutState { |
| 2187 | room_name: "Room 1".into(), |
| 2188 | main: Some(main_target()), |
| 2189 | main_title: "Standup".into(), |
| 2190 | }); |
| 2191 | let (app, mut control) = app_with_commands(cx, room.clone(), None); |
| 2192 | cx.update(|cx| { |
| 2193 | app.update(cx, |state, cx| { |
| 2194 | state.return_to_main_meeting(cx); |
| 2195 | let pending = state |
| 2196 | .call |
| 2197 | .as_ref() |
| 2198 | .unwrap() |
| 2199 | .pending_move |
| 2200 | .clone() |
| 2201 | .expect("a move is pending"); |
| 2202 | assert_eq!(pending.target, main_target()); |
| 2203 | assert_eq!(pending.title, "Standup"); |
| 2204 | assert!(pending.breakout.is_none()); |
| 2205 | }) |
| 2206 | }); |
| 2207 | assert_eq!(control.try_recv_command(), Some(CallCommand::Hangup)); |
| 2208 | let (closed, _control) = app_with_commands(cx, room, None); |
| 2209 | cx.update(|cx| { |
| 2210 | closed.update(cx, |state, _| { |
| 2211 | let call = state.call.as_ref().unwrap(); |
| 2212 | let moved = room_closed_move(call, &EndReason::Remote(EndKind::RoomClosed)) |
| 2213 | .expect("goes back"); |
| 2214 | assert_eq!(moved.target, main_target()); |
| 2215 | assert!(room_closed_move(call, &EndReason::Remote(EndKind::Normal)).is_none()); |
| 2216 | assert!(room_closed_move(call, &EndReason::LocalHangup).is_none()); |
| 2217 | }) |
| 2218 | }); |
| 2219 | let (plain, _control) = app_with_commands(cx, live_meeting(false), None); |
| 2220 | cx.update(|cx| { |
| 2221 | plain.update(cx, |state, _| { |
| 2222 | assert!( |
| 2223 | room_closed_move( |
| 2224 | state.call.as_ref().unwrap(), |
| 2225 | &EndReason::Remote(EndKind::RoomClosed) |
| 2226 | ) |
| 2227 | .is_none() |
| 2228 | ) |
| 2229 | }) |
| 2230 | }); |
| 2231 | } |
| 2232 | |
| 2233 | #[gpui_kit::test] |
| 2234 | fn the_whiteboard_menu_asks_for_the_board_unless_someone_already_shares_one( |
| 2235 | cx: &mut TestAppContext, |
| 2236 | ) { |
| 2237 | let (app, mut control) = app_with_commands(cx, live_meeting(false), None); |
| 2238 | cx.update(|cx| { |
| 2239 | app.update(cx, |state, cx| { |
| 2240 | state.open_call_whiteboard(cx); |
| 2241 | state.apply_call_update( |
| 2242 | 7, |
| 2243 | CallUpdate::Whiteboard(Some(calling::ContentShare { |
| 2244 | session_id: "s".into(), |
| 2245 | presenter: Some("8:orgid:ana".into()), |
| 2246 | subject: "Whiteboard".into(), |
| 2247 | url: Some("https://app.whiteboard.microsoft.com/x".into()), |
| 2248 | whiteboard: true, |
| 2249 | })), |
| 2250 | cx, |
| 2251 | ); |
| 2252 | state.open_call_whiteboard(cx); |
| 2253 | }) |
| 2254 | }); |
| 2255 | assert_eq!( |
| 2256 | control.try_recv_command(), |
| 2257 | Some(CallCommand::OpenWhiteboard { |
| 2258 | title: "Standup".into() |
| 2259 | }) |
| 2260 | ); |
| 2261 | assert_eq!(control.try_recv_command(), None); |
| 2262 | } |
| 2263 | |
| 2264 | #[gpui_kit::test] |
| 2265 | fn the_chat_panel_opens_the_meeting_thread_and_the_badge_counts_only_while_closed( |
| 2266 | cx: &mut TestAppContext, |
| 2267 | ) { |
| 2268 | let (app, _control) = app_with_commands(cx, live_meeting(false), Some("19:list@thread.v2")); |
| 2269 | cx.update(|cx| { |
| 2270 | app.update(cx, |state, cx| { |
| 2271 | state |
| 2272 | .directory |
| 2273 | .unread_counts |
| 2274 | .insert("19:meeting_x@thread.v2".into(), 3); |
| 2275 | assert_eq!(state.call_chat_thread(), None); |
| 2276 | assert_eq!(state.call_chat_unread(), 0); |
| 2277 | state.apply_call_update( |
| 2278 | 7, |
| 2279 | CallUpdate::MeetingChat("19:meeting_x@thread.v2".into()), |
| 2280 | cx, |
| 2281 | ); |
| 2282 | assert_eq!(state.call_chat_unread(), 3); |
| 2283 | state.toggle_call_chat(cx); |
| 2284 | assert_eq!( |
| 2285 | state.call_chat_thread().as_deref(), |
| 2286 | Some("19:meeting_x@thread.v2") |
| 2287 | ); |
| 2288 | assert_eq!(state.call_chat_unread(), 0); |
| 2289 | state.toggle_call_chat(cx); |
| 2290 | assert_eq!(state.call_chat_thread(), None); |
| 2291 | }) |
| 2292 | }); |
| 2293 | } |
| 2294 | |
| 2295 | #[gpui_kit::test] |
| 2296 | fn a_call_without_a_chat_has_no_panel(cx: &mut TestAppContext) { |
| 2297 | let app = app_with_call(cx); |
| 2298 | cx.update(|cx| { |
| 2299 | app.update(cx, |state, cx| { |
| 2300 | state.toggle_call_chat(cx); |
| 2301 | assert!(!state.call.as_ref().unwrap().chat_open); |
| 2302 | }) |
| 2303 | }); |
| 2304 | } |
| 2305 | |
| 2306 | fn app_with_chats(cx: &mut TestAppContext) -> Entity<AppState> { |
| 2307 | cx.update(gpui_kit::init); |
| 2308 | let store = Arc::new(Store::open_in_memory().unwrap()); |
| 2309 | let app = cx.update(|cx| cx.new(|_| AppState::new(store, Mode::default()))); |
| 2310 | cx.update(|cx| { |
| 2311 | app.update(cx, |state, _| { |
| 2312 | state.directory.me = Some(Person { |
| 2313 | user_id: "me-id".into(), |
| 2314 | display_name: "Me".into(), |
| 2315 | }); |
| 2316 | state.sidebar.chats = vec![ |
| 2317 | ChatRecord { |
| 2318 | id: "19:meeting@thread.v2".into(), |
| 2319 | kind: "meeting".into(), |
| 2320 | members: vec![MemberRecord { |
| 2321 | user_id: Some("bea-id".into()), |
| 2322 | display_name: "Bea".into(), |
| 2323 | }], |
| 2324 | ..Default::default() |
| 2325 | }, |
| 2326 | ChatRecord { |
| 2327 | id: "19:dm@unq.gbl.spaces".into(), |
| 2328 | kind: "oneOnOne".into(), |
| 2329 | members: vec![ |
| 2330 | MemberRecord { |
| 2331 | user_id: Some("me-id".into()), |
| 2332 | display_name: "Me".into(), |
| 2333 | }, |
| 2334 | MemberRecord { |
| 2335 | user_id: Some("bea-id".into()), |
| 2336 | display_name: "Bea".into(), |
| 2337 | }, |
| 2338 | ], |
| 2339 | ..Default::default() |
| 2340 | }, |
| 2341 | ]; |
| 2342 | }) |
| 2343 | }); |
| 2344 | app |
| 2345 | } |
| 2346 | |
| 2347 | #[gpui_kit::test] |
| 2348 | fn declining_by_shortcut_only_acts_while_a_ring_shows(cx: &mut TestAppContext) { |
| 2349 | let app = app_with_chats(cx); |
| 2350 | cx.update(|cx| { |
| 2351 | app.update(cx, |state, cx| { |
| 2352 | state.decline_ringing_call(cx); |
| 2353 | assert!(!state.rings.is_ringing()); |
| 2354 | state.demo_incoming_ring(cx); |
| 2355 | assert!(state.rings.is_ringing()); |
| 2356 | state.decline_ringing_call(cx); |
| 2357 | assert!(!state.rings.is_ringing()); |
| 2358 | }) |
| 2359 | }); |
| 2360 | } |
| 2361 | |
| 2362 | #[gpui_kit::test] |
| 2363 | fn picking_another_chat_moves_the_call_to_the_mini_window(cx: &mut TestAppContext) { |
| 2364 | let app = app_with_call(cx); |
| 2365 | cx.update(|cx| { |
| 2366 | app.update(cx, |state, cx| { |
| 2367 | assert!(state.viewing_call()); |
| 2368 | state.select(Selection::Chat("c1".into()), cx); |
| 2369 | assert!(!state.viewing_call()); |
| 2370 | state.show_call(true, cx); |
| 2371 | assert!(state.viewing_call()); |
| 2372 | }) |
| 2373 | }); |
| 2374 | } |
| 2375 | |
| 2376 | #[gpui_kit::test] |
| 2377 | fn an_ended_call_closes_the_view_and_raises_a_notice(cx: &mut TestAppContext) { |
| 2378 | let app = app_with_call(cx); |
| 2379 | let since = Instant::now() - Duration::from_secs(42); |
| 2380 | cx.update(|cx| { |
| 2381 | app.update(cx, |state, cx| { |
| 2382 | state.apply_call_update(7, CallUpdate::State(CallState::Connected { since }), cx); |
| 2383 | assert!(state.call.is_some()); |
| 2384 | state.apply_call_update( |
| 2385 | 7, |
| 2386 | CallUpdate::State(CallState::Ended { |
| 2387 | reason: EndReason::LocalHangup, |
| 2388 | }), |
| 2389 | cx, |
| 2390 | ); |
| 2391 | assert!(state.call.is_none()); |
| 2392 | let notice = state.notice.as_ref().expect("notice"); |
| 2393 | assert_eq!(notice.text, "Call ended 00:42"); |
| 2394 | }) |
| 2395 | }); |
| 2396 | } |
| 2397 | |
| 2398 | #[gpui_kit::test] |
| 2399 | fn a_dropped_call_shows_the_end_screen_and_plays_the_end_tone(cx: &mut TestAppContext) { |
| 2400 | let app = app_with_call(cx); |
| 2401 | let tones = std::rc::Rc::new(std::cell::RefCell::new(Vec::new())); |
| 2402 | let heard = tones.clone(); |
| 2403 | cx.update(|cx| { |
| 2404 | cx.subscribe(&app, move |_, event: &AppEvent, _| { |
| 2405 | if let AppEvent::CallTone(tone) = event { |
| 2406 | heard.borrow_mut().push(*tone); |
| 2407 | } |
| 2408 | }) |
| 2409 | .detach(); |
| 2410 | app.update(cx, |state, cx| { |
| 2411 | state.apply_call_update(7, CallUpdate::State(CallState::Ended { reason: EndReason::Dropped }), cx); |
| 2412 | assert!(state.call.is_none()); |
| 2413 | assert!(state.notice.is_none()); |
| 2414 | let screen = state.call_end.as_ref().expect("end screen"); |
| 2415 | assert_eq!(screen.heading(), "Call dropped"); |
| 2416 | assert_eq!(screen.retry_label(), "Call back"); |
| 2417 | state.dismiss_call_end(cx); |
| 2418 | assert!(state.call_end.is_none()); |
| 2419 | }) |
| 2420 | }); |
| 2421 | assert_eq!(*tones.borrow(), vec![CallTone::CallEnded]); |
| 2422 | } |
| 2423 | |
| 2424 | #[gpui_kit::test] |
| 2425 | fn a_normal_end_keeps_the_notice_and_no_end_screen(cx: &mut TestAppContext) { |
| 2426 | let app = app_with_call(cx); |
| 2427 | cx.update(|cx| { |
| 2428 | app.update(cx, |state, cx| { |
| 2429 | state.apply_call_update(7, CallUpdate::State(CallState::Ended { reason: EndReason::Remote(EndKind::Removed) }), cx); |
| 2430 | assert!(state.call_end.is_none()); |
| 2431 | assert!(state.notice.is_some()); |
| 2432 | }) |
| 2433 | }); |
| 2434 | } |
| 2435 | |
| 2436 | #[gpui_kit::test] |
| 2437 | fn full_window_exists_only_while_someone_shares_and_escape_leaves_it(cx: &mut TestAppContext) { |
| 2438 | let app = app_with_call(cx); |
| 2439 | cx.update(|cx| { |
| 2440 | app.update(cx, |state, cx| { |
| 2441 | state.toggle_stage_fullscreen(cx); |
| 2442 | assert!(!state.stage_fullscreen()); |
| 2443 | state.apply_call_update(7, CallUpdate::ScreenShare(Some("8:orgid:a".into())), cx); |
| 2444 | state.toggle_stage_fullscreen(cx); |
| 2445 | assert!(state.stage_fullscreen()); |
| 2446 | state.leave_stage_fullscreen(cx); |
| 2447 | assert!(!state.stage_fullscreen()); |
| 2448 | state.toggle_stage_fullscreen(cx); |
| 2449 | state.apply_call_update(7, CallUpdate::ScreenShare(None), cx); |
| 2450 | assert!(!state.stage_fullscreen()); |
| 2451 | }) |
| 2452 | }); |
| 2453 | } |
| 2454 | |
| 2455 | #[gpui_kit::test] |
| 2456 | fn a_declined_call_names_who_declined(cx: &mut TestAppContext) { |
| 2457 | let app = app_with_call(cx); |
| 2458 | cx.update(|cx| { |
| 2459 | app.update(cx, |state, cx| { |
| 2460 | state.call.as_mut().unwrap().model.peer_name = "Bea".into(); |
| 2461 | state.apply_call_update( |
| 2462 | 7, |
| 2463 | CallUpdate::State(CallState::Ended { |
| 2464 | reason: EndReason::Remote(EndKind::Declined), |
| 2465 | }), |
| 2466 | cx, |
| 2467 | ); |
| 2468 | assert_eq!(state.notice.as_ref().unwrap().text, "Bea declined"); |
| 2469 | }) |
| 2470 | }); |
| 2471 | } |
| 2472 | |
| 2473 | #[gpui_kit::test] |
| 2474 | fn updates_of_an_older_call_are_ignored(cx: &mut TestAppContext) { |
| 2475 | let app = app_with_call(cx); |
| 2476 | cx.update(|cx| { |
| 2477 | app.update(cx, |state, cx| { |
| 2478 | state.apply_call_update( |
| 2479 | 6, |
| 2480 | CallUpdate::State(CallState::Ended { |
| 2481 | reason: EndReason::Dropped, |
| 2482 | }), |
| 2483 | cx, |
| 2484 | ); |
| 2485 | assert!(state.call.is_some()); |
| 2486 | assert!(state.notice.is_none()); |
| 2487 | }) |
| 2488 | }); |
| 2489 | } |
| 2490 | |
| 2491 | #[gpui_kit::test] |
| 2492 | fn a_ring_that_times_out_becomes_a_missed_call_event(cx: &mut TestAppContext) { |
| 2493 | cx.update(gpui_kit::init); |
| 2494 | let store = Arc::new(Store::open_in_memory().unwrap()); |
| 2495 | let app = cx.update(|cx| cx.new(|_| AppState::new(store, Mode::default()))); |
| 2496 | cx.update(|cx| { |
| 2497 | app.update(cx, |state, cx| { |
| 2498 | state.on_engine_event(EngineEvent::Incoming(demo_ring()), cx); |
| 2499 | assert!(state.rings.is_ringing()); |
| 2500 | state.tick_rings(cx); |
| 2501 | assert!(state.rings.is_ringing()); |
| 2502 | state.on_engine_event( |
| 2503 | EngineEvent::RingEnded { |
| 2504 | ring_id: demo_ring().ring_id, |
| 2505 | kind: EndKind::Cancelled, |
| 2506 | answered_by: None, |
| 2507 | }, |
| 2508 | cx, |
| 2509 | ); |
| 2510 | assert!(!state.rings.is_ringing()); |
| 2511 | }) |
| 2512 | }); |
| 2513 | } |
| 2514 | |
| 2515 | #[gpui_kit::test] |
| 2516 | fn calls_are_refused_for_meeting_chats_and_missing_chats(cx: &mut TestAppContext) { |
| 2517 | let app = app_with_chats(cx); |
| 2518 | cx.update(|cx| { |
| 2519 | app.update(cx, |state, cx| { |
| 2520 | state.start_chat_call("19:meeting@thread.v2", cx); |
| 2521 | assert!(state.call.is_none()); |
| 2522 | assert_eq!( |
| 2523 | state.notice.as_ref().unwrap().text, |
| 2524 | "This chat cannot be called" |
| 2525 | ); |
| 2526 | state.start_chat_call("19:unknown", cx); |
| 2527 | assert!(state.call.is_none()); |
| 2528 | }) |
| 2529 | }); |
| 2530 | } |
| 2531 | |
| 2532 | #[gpui_kit::test] |
| 2533 | fn a_missed_call_finds_the_one_on_one_chat_of_the_caller(cx: &mut TestAppContext) { |
| 2534 | let app = app_with_chats(cx); |
| 2535 | cx.update(|cx| { |
| 2536 | app.update(cx, |state, _| { |
| 2537 | let missed = super::MissedCall { |
| 2538 | caller_mri: "8:orgid:bea-id".into(), |
| 2539 | caller_name: "Bea".into(), |
| 2540 | thread_id: None, |
| 2541 | at: chrono::Utc::now(), |
| 2542 | }; |
| 2543 | assert_eq!( |
| 2544 | state.conversation_of_missed_call(&missed).as_deref(), |
| 2545 | Some("19:dm@unq.gbl.spaces") |
| 2546 | ); |
| 2547 | let direct = super::MissedCall { |
| 2548 | thread_id: Some("19:dm@unq.gbl.spaces".into()), |
| 2549 | ..missed.clone() |
| 2550 | }; |
| 2551 | assert_eq!( |
| 2552 | state.conversation_of_missed_call(&direct).as_deref(), |
| 2553 | Some("19:dm@unq.gbl.spaces") |
| 2554 | ); |
| 2555 | }) |
| 2556 | }); |
| 2557 | } |
| 2558 | |
| 2559 | #[gpui_kit::test] |
| 2560 | fn only_meeting_chats_and_channels_watch_for_a_running_meeting(cx: &mut TestAppContext) { |
| 2561 | let app = app_with_chats(cx); |
| 2562 | cx.update(|cx| { |
| 2563 | app.update(cx, |state, _| { |
| 2564 | assert!(state.watches_live_meeting("19:meeting@thread.v2")); |
| 2565 | assert!(!state.watches_live_meeting("19:dm@unq.gbl.spaces")); |
| 2566 | assert!(!state.watches_live_meeting("19:unknown")); |
| 2567 | }) |
| 2568 | }); |
| 2569 | } |
| 2570 | |
| 2571 | #[gpui_kit::test] |
| 2572 | fn a_live_meeting_shows_until_it_ends(cx: &mut TestAppContext) { |
| 2573 | let app = app_with_chats(cx); |
| 2574 | let meeting = calling::meeting::LiveMeeting { |
| 2575 | thread_id: "19:meeting@thread.v2".into(), |
| 2576 | conversation_url: None, |
| 2577 | expiration: Some(chrono::Utc::now().timestamp() + 600), |
| 2578 | organizer_id: Some("org".into()), |
| 2579 | tenant_id: Some("tenant".into()), |
| 2580 | meeting_code: None, |
| 2581 | passcode: None, |
| 2582 | }; |
| 2583 | cx.update(|cx| { |
| 2584 | app.update(cx, |state, cx| { |
| 2585 | assert!(state.running_meeting("19:meeting@thread.v2").is_none()); |
| 2586 | state.apply_live_meeting("19:meeting@thread.v2".into(), Some(meeting), cx); |
| 2587 | assert!(state.running_meeting("19:meeting@thread.v2").is_some()); |
| 2588 | state.apply_live_meeting("19:meeting@thread.v2".into(), None, cx); |
| 2589 | assert!(state.running_meeting("19:meeting@thread.v2").is_none()); |
| 2590 | }) |
| 2591 | }); |
| 2592 | } |
| 2593 | } |