BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-state / src / call / actions.rs

actions.rs

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