feat(calls): end-of-call tone and end screen like Teams
- play Teams_Call_Ended.mp3 (calls) / Teams_Meet_Up_Leave.mp3 (meetings) on every end except breakout moves - tones fetched at runtime from the Teams CDN, cached in the app cache dir, prefetched at startup, never in git - call/end 0/5000 and 0/5300 classify as EndKind::Removed - end screen for removed from meeting and dropped calls with Dismiss and Rejoin / Call back - demo scenes TEAMS_DEMO_CALL=removed and dropped Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -4,3 +4,4 @@ pub mod badge;
4
4
pub mod platform;
5
5
#[cfg_attr(not(windows), allow(dead_code))]
6
6
pub mod ring_tone;
7
pub mod sound_cache;
@@ -4,3 +4,4 @@ pub mod badge;4
pub mod platform;4
pub mod platform;5
#[cfg_attr(not(windows), allow(dead_code))]5
#[cfg_attr(not(windows), allow(dead_code))]6
pub mod ring_tone;6
pub mod ring_tone;7
pub mod sound_cache;@@ -68,6 +68,8 @@ pub fn set_badge(_handle: NativeHandle, _badge: Option<&Badge>) {}
68
68
69
69
pub fn play_sound() {}
70
70
71
pub fn play_mp3(_bytes: Vec<u8>) {}
72
71
73
pub struct RingTone;
72
74
73
75
pub fn start_ring(_ringtone: Ringtone) -> Option<RingTone> {
@@ -68,6 +68,8 @@ pub fn set_badge(_handle: NativeHandle, _badge: Option<&Badge>) {}68
68
69
pub fn play_sound() {}69
pub fn play_sound() {}70
70
71
pub fn play_mp3(_bytes: Vec<u8>) {}72
71
pub struct RingTone;73
pub struct RingTone;72
74
73
pub fn start_ring(_ringtone: Ringtone) -> Option<RingTone> {75
pub fn start_ring(_ringtone: Ringtone) -> Option<RingTone> {@@ -587,6 +587,18 @@ fn start_cycle(cycle: Vec<f32>) -> Option<RingTone> {
587
587
Some(RingTone { stop })
588
588
}
589
589
590
pub fn play_mp3(bytes: Vec<u8>) {
591
std::thread::spawn(move || {
592
let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {
593
return;
594
};
595
sink.log_on_drop(false);
596
if let Ok(player) = rodio::play(sink.mixer(), Cursor::new(bytes)) {
597
player.sleep_until_end();
598
}
599
});
600
}
601
590
602
pub fn play_sound() {
591
603
std::thread::spawn(|| {
592
604
let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {
@@ -587,6 +587,18 @@ fn start_cycle(cycle: Vec<f32>) -> Option<RingTone> {587
Some(RingTone { stop })587
Some(RingTone { stop })588
}588
}589
589
590
pub fn play_mp3(bytes: Vec<u8>) {591
std::thread::spawn(move || {592
let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {593
return;594
};595
sink.log_on_drop(false);596
if let Ok(player) = rodio::play(sink.mixer(), Cursor::new(bytes)) {597
player.sleep_until_end();598
}599
});600
}601
590
pub fn play_sound() {602
pub fn play_sound() {591
std::thread::spawn(|| {603
std::thread::spawn(|| {592
let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {604
let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {@@ -0,0 +1,105 @@
1
use std::fs;
2
use std::io;
3
use std::path::{Path, PathBuf};
4
5
use gpui_kit::App;
6
7
use super::platform;
8
9
pub const TEAMS_SOUND_BASE_URL: &str =
10
"https://statics.teams.cdn.office.net/evergreen-assets/audio/";
11
const SOUND_DIRECTORY: &str = "sounds";
12
const PARTIAL_SUFFIX: &str = ".partial";
13
14
pub fn cache_directory() -> Option<PathBuf> {
15
directories::ProjectDirs::from("", "", store::DATA_DIR_NAME)
16
.map(|directories| directories.cache_dir().join(SOUND_DIRECTORY))
17
}
18
19
pub fn is_mp3(bytes: &[u8]) -> bool {
20
bytes.starts_with(b"ID3") || matches!(bytes, [0xFF, second, ..] if second & 0xE0 == 0xE0)
21
}
22
23
pub fn read_cached(directory: &Path, file_name: &str) -> Option<Vec<u8>> {
24
fs::read(directory.join(file_name))
25
.ok()
26
.filter(|bytes| is_mp3(bytes))
27
}
28
29
pub fn write_cached(directory: &Path, file_name: &str, bytes: &[u8]) -> io::Result<()> {
30
fs::create_dir_all(directory)?;
31
let partial = directory.join(format!("{file_name}{PARTIAL_SUFFIX}"));
32
fs::write(&partial, bytes)?;
33
fs::rename(&partial, directory.join(file_name))
34
}
35
36
fn load(file_name: &'static str, cx: &App) -> gpui_kit::Task<Option<Vec<u8>>> {
37
let client = cx.http_client();
38
cx.background_executor().spawn(async move {
39
let directory = cache_directory()?;
40
if let Some(bytes) = read_cached(&directory, file_name) {
41
return Some(bytes);
42
}
43
use futures_util::AsyncReadExt as _;
44
let url = format!("{TEAMS_SOUND_BASE_URL}{file_name}");
45
let mut response = client.get(&url, ().into(), true).await.ok()?;
46
let mut body = Vec::new();
47
response.body_mut().read_to_end(&mut body).await.ok()?;
48
if !response.status().is_success() || !is_mp3(&body) {
49
log::warn!(
50
"teams sound {file_name} not loaded: status {}",
51
response.status()
52
);
53
return None;
54
}
55
if let Err(error) = write_cached(&directory, file_name, &body) {
56
log::warn!("teams sound {file_name} not cached: {error}");
57
}
58
Some(body)
59
})
60
}
61
62
pub fn prefetch(file_names: &[&'static str], cx: &App) {
63
for file_name in file_names {
64
load(file_name, cx).detach();
65
}
66
}
67
68
pub fn play(file_name: &'static str, cx: &App) {
69
let loading = load(file_name, cx);
70
cx.background_executor()
71
.spawn(async move {
72
if let Some(bytes) = loading.await {
73
platform::play_mp3(bytes);
74
}
75
})
76
.detach();
77
}
78
79
#[cfg(test)]
80
mod tests {
81
use super::*;
82
83
#[test]
84
fn mp3_files_start_with_a_tag_or_a_frame_sync() {
85
assert!(is_mp3(b"ID3\x04\x00"));
86
assert!(is_mp3(&[0xFF, 0xFB, 0x90]));
87
assert!(!is_mp3(b"<?xml version"));
88
assert!(!is_mp3(&[]));
89
}
90
91
#[test]
92
fn a_cached_sound_round_trips_and_junk_is_ignored() {
93
let directory = tempfile::tempdir().unwrap();
94
let sounds = directory.path().join("sounds");
95
write_cached(&sounds, "end.mp3", b"ID3 tone").unwrap();
96
assert_eq!(
97
read_cached(&sounds, "end.mp3").as_deref(),
98
Some(&b"ID3 tone"[..])
99
);
100
assert!(!sounds.join("end.mp3.partial").exists());
101
write_cached(&sounds, "junk.mp3", b"<Error/>").unwrap();
102
assert_eq!(read_cached(&sounds, "junk.mp3"), None);
103
assert_eq!(read_cached(&sounds, "missing.mp3"), None);
104
}
105
}
@@ -0,0 +1,105 @@1
use std::fs;2
use std::io;3
use std::path::{Path, PathBuf};4
5
use gpui_kit::App;6
7
use super::platform;8
9
pub const TEAMS_SOUND_BASE_URL: &str =10
"https://statics.teams.cdn.office.net/evergreen-assets/audio/";11
const SOUND_DIRECTORY: &str = "sounds";12
const PARTIAL_SUFFIX: &str = ".partial";13
14
pub fn cache_directory() -> Option<PathBuf> {15
directories::ProjectDirs::from("", "", store::DATA_DIR_NAME)16
.map(|directories| directories.cache_dir().join(SOUND_DIRECTORY))17
}18
19
pub fn is_mp3(bytes: &[u8]) -> bool {20
bytes.starts_with(b"ID3") || matches!(bytes, [0xFF, second, ..] if second & 0xE0 == 0xE0)21
}22
23
pub fn read_cached(directory: &Path, file_name: &str) -> Option<Vec<u8>> {24
fs::read(directory.join(file_name))25
.ok()26
.filter(|bytes| is_mp3(bytes))27
}28
29
pub fn write_cached(directory: &Path, file_name: &str, bytes: &[u8]) -> io::Result<()> {30
fs::create_dir_all(directory)?;31
let partial = directory.join(format!("{file_name}{PARTIAL_SUFFIX}"));32
fs::write(&partial, bytes)?;33
fs::rename(&partial, directory.join(file_name))34
}35
36
fn load(file_name: &'static str, cx: &App) -> gpui_kit::Task<Option<Vec<u8>>> {37
let client = cx.http_client();38
cx.background_executor().spawn(async move {39
let directory = cache_directory()?;40
if let Some(bytes) = read_cached(&directory, file_name) {41
return Some(bytes);42
}43
use futures_util::AsyncReadExt as _;44
let url = format!("{TEAMS_SOUND_BASE_URL}{file_name}");45
let mut response = client.get(&url, ().into(), true).await.ok()?;46
let mut body = Vec::new();47
response.body_mut().read_to_end(&mut body).await.ok()?;48
if !response.status().is_success() || !is_mp3(&body) {49
log::warn!(50
"teams sound {file_name} not loaded: status {}",51
response.status()52
);53
return None;54
}55
if let Err(error) = write_cached(&directory, file_name, &body) {56
log::warn!("teams sound {file_name} not cached: {error}");57
}58
Some(body)59
})60
}61
62
pub fn prefetch(file_names: &[&'static str], cx: &App) {63
for file_name in file_names {64
load(file_name, cx).detach();65
}66
}67
68
pub fn play(file_name: &'static str, cx: &App) {69
let loading = load(file_name, cx);70
cx.background_executor()71
.spawn(async move {72
if let Some(bytes) = loading.await {73
platform::play_mp3(bytes);74
}75
})76
.detach();77
}78
79
#[cfg(test)]80
mod tests {81
use super::*;82
83
#[test]84
fn mp3_files_start_with_a_tag_or_a_frame_sync() {85
assert!(is_mp3(b"ID3\x04\x00"));86
assert!(is_mp3(&[0xFF, 0xFB, 0x90]));87
assert!(!is_mp3(b"<?xml version"));88
assert!(!is_mp3(&[]));89
}90
91
#[test]92
fn a_cached_sound_round_trips_and_junk_is_ignored() {93
let directory = tempfile::tempdir().unwrap();94
let sounds = directory.path().join("sounds");95
write_cached(&sounds, "end.mp3", b"ID3 tone").unwrap();96
assert_eq!(97
read_cached(&sounds, "end.mp3").as_deref(),98
Some(&b"ID3 tone"[..])99
);100
assert!(!sounds.join("end.mp3.partial").exists());101
write_cached(&sounds, "junk.mp3", b"<Error/>").unwrap();102
assert_eq!(read_cached(&sounds, "junk.mp3"), None);103
assert_eq!(read_cached(&sounds, "missing.mp3"), None);104
}105
}@@ -16,6 +16,7 @@ use calling::timeline::TimelineEntry;
16
16
use calling::{CallDiagnostics, SdpLine, SdpSummary, StatsSample};
17
17
18
18
use super::demo_scene::self_view;
19
use super::end_screen::EndCause;
19
20
use tokio::time::{interval, sleep};
20
21
21
22
use super::model::{ECHO_MRI, ECHO_NAME};
@@ -104,6 +105,8 @@ pub enum DemoScene {
104
105
MiniOff,
105
106
MiniShare,
106
107
Blocked,
108
Removed,
109
Dropped,
107
110
}
108
111
109
112
impl DemoScene {
@@ -124,6 +127,8 @@ impl DemoScene {
124
127
"mini-off" => DemoScene::MiniOff,
125
128
"mini-share" => DemoScene::MiniShare,
126
129
"blocked" => DemoScene::Blocked,
130
"removed" => DemoScene::Removed,
131
"dropped" => DemoScene::Dropped,
127
132
_ => return None,
128
133
})
129
134
}
@@ -143,6 +148,14 @@ impl DemoScene {
143
148
)
144
149
}
145
150
151
pub fn end_cause(self) -> Option<EndCause> {
152
match self {
153
DemoScene::Removed => Some(EndCause::Removed),
154
DemoScene::Dropped => Some(EndCause::Dropped),
155
_ => None,
156
}
157
}
158
146
159
pub fn minimized(self) -> bool {
147
160
matches!(self, DemoScene::Mini | DemoScene::MiniOff | DemoScene::MiniShare)
148
161
}
@@ -450,6 +463,8 @@ fn start_scene(control: &CallControl, scene: DemoScene) {
450
463
| DemoScene::Gallery
451
464
| DemoScene::Sharing
452
465
| DemoScene::Blocked
466
| DemoScene::Removed
467
| DemoScene::Dropped
453
468
| DemoScene::Plain => {}
454
469
}
455
470
}
@@ -16,6 +16,7 @@ use calling::timeline::TimelineEntry;16
use calling::{CallDiagnostics, SdpLine, SdpSummary, StatsSample};16
use calling::{CallDiagnostics, SdpLine, SdpSummary, StatsSample};17
17
18
use super::demo_scene::self_view;18
use super::demo_scene::self_view;19
use super::end_screen::EndCause;19
use tokio::time::{interval, sleep};20
use tokio::time::{interval, sleep};20
21
21
use super::model::{ECHO_MRI, ECHO_NAME};22
use super::model::{ECHO_MRI, ECHO_NAME};@@ -104,6 +105,8 @@ pub enum DemoScene {104
MiniOff,105
MiniOff,105
MiniShare,106
MiniShare,106
Blocked,107
Blocked,108
Removed,109
Dropped,107
}110
}108
111
109
impl DemoScene {112
impl DemoScene {@@ -124,6 +127,8 @@ impl DemoScene {124
"mini-off" => DemoScene::MiniOff,127
"mini-off" => DemoScene::MiniOff,125
"mini-share" => DemoScene::MiniShare,128
"mini-share" => DemoScene::MiniShare,126
"blocked" => DemoScene::Blocked,129
"blocked" => DemoScene::Blocked,130
"removed" => DemoScene::Removed,131
"dropped" => DemoScene::Dropped,127
_ => return None,132
_ => return None,128
})133
})129
}134
}@@ -143,6 +148,14 @@ impl DemoScene {143
)148
)144
}149
}145
150
151
pub fn end_cause(self) -> Option<EndCause> {152
match self {153
DemoScene::Removed => Some(EndCause::Removed),154
DemoScene::Dropped => Some(EndCause::Dropped),155
_ => None,156
}157
}158
146
pub fn minimized(self) -> bool {159
pub fn minimized(self) -> bool {147
matches!(self, DemoScene::Mini | DemoScene::MiniOff | DemoScene::MiniShare)160
matches!(self, DemoScene::Mini | DemoScene::MiniOff | DemoScene::MiniShare)148
}161
}@@ -450,6 +463,8 @@ fn start_scene(control: &CallControl, scene: DemoScene) {450
| DemoScene::Gallery463
| DemoScene::Gallery451
| DemoScene::Sharing464
| DemoScene::Sharing452
| DemoScene::Blocked465
| DemoScene::Blocked466
| DemoScene::Removed467
| DemoScene::Dropped453
| DemoScene::Plain => {}468
| DemoScene::Plain => {}454
}469
}455
}470
}@@ -0,0 +1,209 @@
1
use calling::{EndKind, EndReason, MeetingTarget};
2
3
use super::model::{ActiveCall, CallKind};
4
5
const ORGID_PREFIX: &str = "8:orgid:";
6
pub const DISMISS_LABEL: &str = "Dismiss";
7
8
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9
pub enum EndTone {
10
CallEnded,
11
MeetingLeft,
12
}
13
14
impl EndTone {
15
pub const ALL: [EndTone; 2] = [EndTone::CallEnded, EndTone::MeetingLeft];
16
17
pub fn file_name(self) -> &'static str {
18
match self {
19
EndTone::CallEnded => "Teams_Call_Ended.mp3",
20
EndTone::MeetingLeft => "Teams_Meet_Up_Leave.mp3",
21
}
22
}
23
}
24
25
pub fn end_tone(kind: CallKind, moving_rooms: bool) -> Option<EndTone> {
26
if moving_rooms {
27
return None;
28
}
29
Some(match kind {
30
CallKind::Meeting => EndTone::MeetingLeft,
31
CallKind::Test | CallKind::Direct | CallKind::Group => EndTone::CallEnded,
32
})
33
}
34
35
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36
pub enum EndCause {
37
Removed,
38
Dropped,
39
}
40
41
pub fn end_cause(reason: &EndReason, kind: CallKind) -> Option<EndCause> {
42
match reason {
43
EndReason::Dropped => Some(EndCause::Dropped),
44
EndReason::Remote(EndKind::Removed) if kind == CallKind::Meeting => Some(EndCause::Removed),
45
_ => None,
46
}
47
}
48
49
#[derive(Debug, Clone, PartialEq)]
50
pub struct EndPeer {
51
pub user_id: Option<String>,
52
pub name: String,
53
}
54
55
#[derive(Debug, Clone, PartialEq)]
56
pub struct CallEndScreen {
57
pub cause: EndCause,
58
pub kind: CallKind,
59
pub title: String,
60
pub conversation_id: Option<String>,
61
pub meeting_target: Option<MeetingTarget>,
62
pub peer: Option<EndPeer>,
63
}
64
65
impl CallEndScreen {
66
pub fn for_call(call: &ActiveCall, reason: &EndReason) -> Option<Self> {
67
let model = &call.model;
68
let cause = end_cause(reason, model.kind)?;
69
let peer = (model.kind == CallKind::Direct)
70
.then(|| model.tiles.first())
71
.flatten()
72
.map(|tile| EndPeer {
73
user_id: tile
74
.user_id
75
.clone()
76
.or_else(|| tile.mri.strip_prefix(ORGID_PREFIX).map(str::to_owned)),
77
name: tile.name.clone(),
78
});
79
Some(CallEndScreen {
80
cause,
81
kind: model.kind,
82
title: model.title.clone(),
83
conversation_id: call.conversation_id.clone(),
84
meeting_target: call.meeting_target.clone(),
85
peer,
86
})
87
}
88
89
fn is_two_party(&self) -> bool {
90
matches!(self.kind, CallKind::Direct | CallKind::Test)
91
}
92
93
pub fn heading(&self) -> &'static str {
94
match (self.cause, self.kind) {
95
(EndCause::Removed, CallKind::Meeting) => "Removed from the meeting",
96
(EndCause::Removed, _) => "Removed from the call",
97
(EndCause::Dropped, _) => "Call dropped",
98
}
99
}
100
101
pub fn description(&self) -> &'static str {
102
match self.cause {
103
EndCause::Removed if self.kind == CallKind::Meeting => {
104
"Someone just removed you from the meeting. You can try to rejoin."
105
}
106
EndCause::Removed => "Someone just removed you from the call. You can try to rejoin.",
107
EndCause::Dropped if self.is_two_party() => {
108
"Sorry we couldn't reconnect your call. Make sure you have an internet connection and try calling back."
109
}
110
EndCause::Dropped => {
111
"Sorry we couldn't get you back into the meeting. Make sure you have an internet connection and try to rejoin."
112
}
113
}
114
}
115
116
pub fn retry_label(&self) -> &'static str {
117
match self.cause {
118
EndCause::Dropped if self.is_two_party() => "Call back",
119
EndCause::Removed | EndCause::Dropped => "Rejoin",
120
}
121
}
122
123
pub fn can_retry(&self) -> bool {
124
match self.kind {
125
CallKind::Test => true,
126
CallKind::Meeting => self.meeting_target.is_some(),
127
CallKind::Direct | CallKind::Group => self.conversation_id.is_some(),
128
}
129
}
130
}
131
132
#[cfg(test)]
133
mod tests {
134
use super::*;
135
136
fn screen(cause: EndCause, kind: CallKind) -> CallEndScreen {
137
CallEndScreen {
138
cause,
139
kind,
140
title: "Standup".to_owned(),
141
conversation_id: Some("19:chat".to_owned()),
142
meeting_target: None,
143
peer: None,
144
}
145
}
146
147
#[test]
148
fn meetings_leave_with_the_meetup_tone_and_calls_with_the_call_tone() {
149
assert_eq!(
150
end_tone(CallKind::Meeting, false),
151
Some(EndTone::MeetingLeft)
152
);
153
assert_eq!(end_tone(CallKind::Direct, false), Some(EndTone::CallEnded));
154
assert_eq!(end_tone(CallKind::Group, false), Some(EndTone::CallEnded));
155
assert_eq!(end_tone(CallKind::Test, false), Some(EndTone::CallEnded));
156
assert_eq!(end_tone(CallKind::Meeting, true), None);
157
}
158
159
#[test]
160
fn only_drops_and_removals_from_meetings_get_an_end_screen() {
161
let removed = EndReason::Remote(EndKind::Removed);
162
assert_eq!(
163
end_cause(&EndReason::Dropped, CallKind::Direct),
164
Some(EndCause::Dropped)
165
);
166
assert_eq!(
167
end_cause(&removed, CallKind::Meeting),
168
Some(EndCause::Removed)
169
);
170
assert_eq!(end_cause(&removed, CallKind::Direct), None);
171
assert_eq!(end_cause(&EndReason::LocalHangup, CallKind::Meeting), None);
172
assert_eq!(
173
end_cause(&EndReason::Remote(EndKind::Normal), CallKind::Direct),
174
None
175
);
176
}
177
178
#[test]
179
fn texts_follow_teams_per_case() {
180
let removed = screen(EndCause::Removed, CallKind::Meeting);
181
assert_eq!(removed.heading(), "Removed from the meeting");
182
assert_eq!(removed.retry_label(), "Rejoin");
183
let dropped_call = screen(EndCause::Dropped, CallKind::Direct);
184
assert_eq!(dropped_call.heading(), "Call dropped");
185
assert_eq!(dropped_call.retry_label(), "Call back");
186
assert!(dropped_call.description().contains("try calling back"));
187
let dropped_meeting = screen(EndCause::Dropped, CallKind::Meeting);
188
assert_eq!(dropped_meeting.retry_label(), "Rejoin");
189
assert!(
190
dropped_meeting
191
.description()
192
.contains("back into the meeting")
193
);
194
}
195
196
#[test]
197
fn a_meeting_needs_its_target_to_rejoin() {
198
let mut meeting = screen(EndCause::Removed, CallKind::Meeting);
199
assert!(!meeting.can_retry());
200
meeting.meeting_target = Some(MeetingTarget {
201
thread_id: "19:meeting".to_owned(),
202
tenant_id: "tenant".to_owned(),
203
organizer_id: "organizer".to_owned(),
204
meeting_data: None,
205
});
206
assert!(meeting.can_retry());
207
assert!(screen(EndCause::Dropped, CallKind::Group).can_retry());
208
}
209
}
@@ -0,0 +1,209 @@1
use calling::{EndKind, EndReason, MeetingTarget};2
3
use super::model::{ActiveCall, CallKind};4
5
const ORGID_PREFIX: &str = "8:orgid:";6
pub const DISMISS_LABEL: &str = "Dismiss";7
8
#[derive(Debug, Clone, Copy, PartialEq, Eq)]9
pub enum EndTone {10
CallEnded,11
MeetingLeft,12
}13
14
impl EndTone {15
pub const ALL: [EndTone; 2] = [EndTone::CallEnded, EndTone::MeetingLeft];16
17
pub fn file_name(self) -> &'static str {18
match self {19
EndTone::CallEnded => "Teams_Call_Ended.mp3",20
EndTone::MeetingLeft => "Teams_Meet_Up_Leave.mp3",21
}22
}23
}24
25
pub fn end_tone(kind: CallKind, moving_rooms: bool) -> Option<EndTone> {26
if moving_rooms {27
return None;28
}29
Some(match kind {30
CallKind::Meeting => EndTone::MeetingLeft,31
CallKind::Test | CallKind::Direct | CallKind::Group => EndTone::CallEnded,32
})33
}34
35
#[derive(Debug, Clone, Copy, PartialEq, Eq)]36
pub enum EndCause {37
Removed,38
Dropped,39
}40
41
pub fn end_cause(reason: &EndReason, kind: CallKind) -> Option<EndCause> {42
match reason {43
EndReason::Dropped => Some(EndCause::Dropped),44
EndReason::Remote(EndKind::Removed) if kind == CallKind::Meeting => Some(EndCause::Removed),45
_ => None,46
}47
}48
49
#[derive(Debug, Clone, PartialEq)]50
pub struct EndPeer {51
pub user_id: Option<String>,52
pub name: String,53
}54
55
#[derive(Debug, Clone, PartialEq)]56
pub struct CallEndScreen {57
pub cause: EndCause,58
pub kind: CallKind,59
pub title: String,60
pub conversation_id: Option<String>,61
pub meeting_target: Option<MeetingTarget>,62
pub peer: Option<EndPeer>,63
}64
65
impl CallEndScreen {66
pub fn for_call(call: &ActiveCall, reason: &EndReason) -> Option<Self> {67
let model = &call.model;68
let cause = end_cause(reason, model.kind)?;69
let peer = (model.kind == CallKind::Direct)70
.then(|| model.tiles.first())71
.flatten()72
.map(|tile| EndPeer {73
user_id: tile74
.user_id75
.clone()76
.or_else(|| tile.mri.strip_prefix(ORGID_PREFIX).map(str::to_owned)),77
name: tile.name.clone(),78
});79
Some(CallEndScreen {80
cause,81
kind: model.kind,82
title: model.title.clone(),83
conversation_id: call.conversation_id.clone(),84
meeting_target: call.meeting_target.clone(),85
peer,86
})87
}88
89
fn is_two_party(&self) -> bool {90
matches!(self.kind, CallKind::Direct | CallKind::Test)91
}92
93
pub fn heading(&self) -> &'static str {94
match (self.cause, self.kind) {95
(EndCause::Removed, CallKind::Meeting) => "Removed from the meeting",96
(EndCause::Removed, _) => "Removed from the call",97
(EndCause::Dropped, _) => "Call dropped",98
}99
}100
101
pub fn description(&self) -> &'static str {102
match self.cause {103
EndCause::Removed if self.kind == CallKind::Meeting => {104
"Someone just removed you from the meeting. You can try to rejoin."105
}106
EndCause::Removed => "Someone just removed you from the call. You can try to rejoin.",107
EndCause::Dropped if self.is_two_party() => {108
"Sorry we couldn't reconnect your call. Make sure you have an internet connection and try calling back."109
}110
EndCause::Dropped => {111
"Sorry we couldn't get you back into the meeting. Make sure you have an internet connection and try to rejoin."112
}113
}114
}115
116
pub fn retry_label(&self) -> &'static str {117
match self.cause {118
EndCause::Dropped if self.is_two_party() => "Call back",119
EndCause::Removed | EndCause::Dropped => "Rejoin",120
}121
}122
123
pub fn can_retry(&self) -> bool {124
match self.kind {125
CallKind::Test => true,126
CallKind::Meeting => self.meeting_target.is_some(),127
CallKind::Direct | CallKind::Group => self.conversation_id.is_some(),128
}129
}130
}131
132
#[cfg(test)]133
mod tests {134
use super::*;135
136
fn screen(cause: EndCause, kind: CallKind) -> CallEndScreen {137
CallEndScreen {138
cause,139
kind,140
title: "Standup".to_owned(),141
conversation_id: Some("19:chat".to_owned()),142
meeting_target: None,143
peer: None,144
}145
}146
147
#[test]148
fn meetings_leave_with_the_meetup_tone_and_calls_with_the_call_tone() {149
assert_eq!(150
end_tone(CallKind::Meeting, false),151
Some(EndTone::MeetingLeft)152
);153
assert_eq!(end_tone(CallKind::Direct, false), Some(EndTone::CallEnded));154
assert_eq!(end_tone(CallKind::Group, false), Some(EndTone::CallEnded));155
assert_eq!(end_tone(CallKind::Test, false), Some(EndTone::CallEnded));156
assert_eq!(end_tone(CallKind::Meeting, true), None);157
}158
159
#[test]160
fn only_drops_and_removals_from_meetings_get_an_end_screen() {161
let removed = EndReason::Remote(EndKind::Removed);162
assert_eq!(163
end_cause(&EndReason::Dropped, CallKind::Direct),164
Some(EndCause::Dropped)165
);166
assert_eq!(167
end_cause(&removed, CallKind::Meeting),168
Some(EndCause::Removed)169
);170
assert_eq!(end_cause(&removed, CallKind::Direct), None);171
assert_eq!(end_cause(&EndReason::LocalHangup, CallKind::Meeting), None);172
assert_eq!(173
end_cause(&EndReason::Remote(EndKind::Normal), CallKind::Direct),174
None175
);176
}177
178
#[test]179
fn texts_follow_teams_per_case() {180
let removed = screen(EndCause::Removed, CallKind::Meeting);181
assert_eq!(removed.heading(), "Removed from the meeting");182
assert_eq!(removed.retry_label(), "Rejoin");183
let dropped_call = screen(EndCause::Dropped, CallKind::Direct);184
assert_eq!(dropped_call.heading(), "Call dropped");185
assert_eq!(dropped_call.retry_label(), "Call back");186
assert!(dropped_call.description().contains("try calling back"));187
let dropped_meeting = screen(EndCause::Dropped, CallKind::Meeting);188
assert_eq!(dropped_meeting.retry_label(), "Rejoin");189
assert!(190
dropped_meeting191
.description()192
.contains("back into the meeting")193
);194
}195
196
#[test]197
fn a_meeting_needs_its_target_to_rejoin() {198
let mut meeting = screen(EndCause::Removed, CallKind::Meeting);199
assert!(!meeting.can_retry());200
meeting.meeting_target = Some(MeetingTarget {201
thread_id: "19:meeting".to_owned(),202
tenant_id: "tenant".to_owned(),203
organizer_id: "organizer".to_owned(),204
meeting_data: None,205
});206
assert!(meeting.can_retry());207
assert!(screen(EndCause::Dropped, CallKind::Group).can_retry());208
}209
}@@ -4,6 +4,7 @@ pub mod bubbles;
4
4
pub mod caption_style;
5
5
pub mod demo;
6
6
pub mod demo_scene;
7
pub mod end_screen;
7
8
pub mod fullscreen;
8
9
pub mod health;
9
10
pub mod media;
@@ -4,6 +4,7 @@ pub mod bubbles;4
pub mod caption_style;4
pub mod caption_style;5
pub mod demo;5
pub mod demo;6
pub mod demo_scene;6
pub mod demo_scene;7
pub mod end_screen;7
pub mod fullscreen;8
pub mod fullscreen;8
pub mod health;9
pub mod health;9
pub mod media;10
pub mod media;@@ -71,6 +71,7 @@ pub enum AppEvent {
71
71
MissedCall(MissedCall),
72
72
MeetingReminder,
73
73
MeetingChime,
74
CallEndTone(crate::call::end_screen::EndTone),
74
75
}
75
76
76
77
#[derive(Debug, Clone, Copy, Default)]
@@ -127,6 +128,7 @@ pub struct AppState {
127
128
pub profile_request: Option<ProfileRequest>,
128
129
pub call: Option<ActiveCall>,
129
130
pub held_call: Option<ActiveCall>,
131
pub call_end: Option<crate::call::end_screen::CallEndScreen>,
130
132
pub call_media: Option<Entity<CallMedia>>,
131
133
pub call_launcher: Option<Arc<CallLauncher>>,
132
134
pub call_count: u64,
@@ -273,6 +275,7 @@ impl AppState {
273
275
profiles: ProfileCache::new(),
274
276
profile_request: None,
275
277
call: None,
278
call_end: None,
276
279
held_call: None,
277
280
call_media: None,
278
281
call_launcher: None,
@@ -774,6 +777,7 @@ impl AppState {
774
777
pub fn select(&mut self, selection: Selection, cx: &mut Context<Self>) {
775
778
self.show_call(false, cx);
776
779
self.cancel_prejoin(cx);
780
self.call_end = None;
777
781
let was_drafting = std::mem::take(&mut self.new_chat);
778
782
if !was_drafting && self.selection.as_ref() == Some(&selection) {
779
783
return;
@@ -71,6 +71,7 @@ pub enum AppEvent {71
MissedCall(MissedCall),71
MissedCall(MissedCall),72
MeetingReminder,72
MeetingReminder,73
MeetingChime,73
MeetingChime,74
CallEndTone(crate::call::end_screen::EndTone),74
}75
}75
76
76
#[derive(Debug, Clone, Copy, Default)]77
#[derive(Debug, Clone, Copy, Default)]@@ -127,6 +128,7 @@ pub struct AppState {127
pub profile_request: Option<ProfileRequest>,128
pub profile_request: Option<ProfileRequest>,128
pub call: Option<ActiveCall>,129
pub call: Option<ActiveCall>,129
pub held_call: Option<ActiveCall>,130
pub held_call: Option<ActiveCall>,131
pub call_end: Option<crate::call::end_screen::CallEndScreen>,130
pub call_media: Option<Entity<CallMedia>>,132
pub call_media: Option<Entity<CallMedia>>,131
pub call_launcher: Option<Arc<CallLauncher>>,133
pub call_launcher: Option<Arc<CallLauncher>>,132
pub call_count: u64,134
pub call_count: u64,@@ -273,6 +275,7 @@ impl AppState {273
profiles: ProfileCache::new(),275
profiles: ProfileCache::new(),274
profile_request: None,276
profile_request: None,275
call: None,277
call: None,278
call_end: None,276
held_call: None,279
held_call: None,277
call_media: None,280
call_media: None,278
call_launcher: None,281
call_launcher: None,@@ -774,6 +777,7 @@ impl AppState {774
pub fn select(&mut self, selection: Selection, cx: &mut Context<Self>) {777
pub fn select(&mut self, selection: Selection, cx: &mut Context<Self>) {775
self.show_call(false, cx);778
self.show_call(false, cx);776
self.cancel_prejoin(cx);779
self.cancel_prejoin(cx);780
self.call_end = None;777
let was_drafting = std::mem::take(&mut self.new_chat);781
let was_drafting = std::mem::take(&mut self.new_chat);778
if !was_drafting && self.selection.as_ref() == Some(&selection) {782
if !was_drafting && self.selection.as_ref() == Some(&selection) {779
return;783
return;@@ -17,6 +17,7 @@ use super::demo::{
17
17
use super::features::{TransferCandidate, room_closed_move};
18
18
use super::media::CallMedia;
19
19
use super::mic::save_mic;
20
use super::end_screen::{CallEndScreen, end_tone};
20
21
use super::model::{ActiveCall, CallKind, CallModel, ConsultTransfer, ended_notice};
21
22
use super::prejoin::{DemoMeeting, MeetingJoin};
22
23
use super::report::{
@@ -240,6 +241,7 @@ impl AppState {
240
241
) {
241
242
self.call_count += 1;
242
243
let call_id = self.call_count;
244
self.call_end = None;
243
245
let CallHandle {
244
246
commands,
245
247
updates,
@@ -551,6 +553,12 @@ impl AppState {
551
553
.pending_move
552
554
.take()
553
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::CallEndTone(tone));
558
}
559
let end_screen = (call.viewing && !back_to_held && next_move.is_none())
560
.then(|| CallEndScreen::for_call(call, &reason))
561
.flatten();
554
562
call.pictures.clear(cx);
555
563
if let Some(thread) = call.chat_thread() {
556
564
crate::agent_api::clear_captions(thread, cx);
@@ -560,9 +568,10 @@ impl AppState {
560
568
if back_to_held {
561
569
self.call = self.held_call.take();
562
570
}
563
match next_move {
564
Some(next_move) => self.join_moved_call(next_move, cx),
565
None => self.raise_notice(notice, None, cx),
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),
566
575
}
567
576
self.refresh_call_history_after_call(cx);
568
577
cx.emit(AppEvent::Call);
@@ -1085,6 +1094,10 @@ impl AppState {
1085
1094
if self.call.is_some() {
1086
1095
return;
1087
1096
}
1097
if let Some(cause) = scene.end_cause() {
1098
self.demo_call_end(cause, cx);
1099
return;
1100
}
1088
1101
let (script, model, conversation_id) = if scene.is_one_to_one() {
1089
1102
(
1090
1103
DemoCall::People(vec![demo_caller()]),
@@ -1359,6 +1372,7 @@ mod tests {
1359
1372
use crate::call::background::BackgroundPick;
1360
1373
use crate::call::{CaptionPosition, CaptionSize, RecordAction, ViewSettings};
1361
1374
use crate::call::demo::demo_ring;
1375
use crate::call::end_screen::EndTone;
1362
1376
use crate::call::features::room_closed_move;
1363
1377
use crate::call::model::BreakoutState;
1364
1378
use crate::data::Person;
@@ -2343,6 +2357,44 @@ mod tests {
2343
2357
});
2344
2358
}
2345
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::CallEndTone(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![EndTone::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
2346
2398
#[gpui_kit::test]
2347
2399
fn full_window_exists_only_while_someone_shares_and_escape_leaves_it(cx: &mut TestAppContext) {
2348
2400
let app = app_with_call(cx);
@@ -17,6 +17,7 @@ use super::demo::{17
use super::features::{TransferCandidate, room_closed_move};17
use super::features::{TransferCandidate, room_closed_move};18
use super::media::CallMedia;18
use super::media::CallMedia;19
use super::mic::save_mic;19
use super::mic::save_mic;20
use super::end_screen::{CallEndScreen, end_tone};20
use super::model::{ActiveCall, CallKind, CallModel, ConsultTransfer, ended_notice};21
use super::model::{ActiveCall, CallKind, CallModel, ConsultTransfer, ended_notice};21
use super::prejoin::{DemoMeeting, MeetingJoin};22
use super::prejoin::{DemoMeeting, MeetingJoin};22
use super::report::{23
use super::report::{@@ -240,6 +241,7 @@ impl AppState {240
) {241
) {241
self.call_count += 1;242
self.call_count += 1;242
let call_id = self.call_count;243
let call_id = self.call_count;244
self.call_end = None;243
let CallHandle {245
let CallHandle {244
commands,246
commands,245
updates,247
updates,@@ -551,6 +553,12 @@ impl AppState {551
.pending_move553
.pending_move552
.take()554
.take()553
.or_else(|| room_closed_move(call, &reason));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::CallEndTone(tone));558
}559
let end_screen = (call.viewing && !back_to_held && next_move.is_none())560
.then(|| CallEndScreen::for_call(call, &reason))561
.flatten();554
call.pictures.clear(cx);562
call.pictures.clear(cx);555
if let Some(thread) = call.chat_thread() {563
if let Some(thread) = call.chat_thread() {556
crate::agent_api::clear_captions(thread, cx);564
crate::agent_api::clear_captions(thread, cx);@@ -560,9 +568,10 @@ impl AppState {560
if back_to_held {568
if back_to_held {561
self.call = self.held_call.take();569
self.call = self.held_call.take();562
}570
}563
match next_move {571
match (next_move, end_screen) {564
Some(next_move) => self.join_moved_call(next_move, cx),572
(Some(next_move), _) => self.join_moved_call(next_move, cx),565
None => self.raise_notice(notice, None, cx),573
(None, Some(end_screen)) => self.call_end = Some(end_screen),574
(None, None) => self.raise_notice(notice, None, cx),566
}575
}567
self.refresh_call_history_after_call(cx);576
self.refresh_call_history_after_call(cx);568
cx.emit(AppEvent::Call);577
cx.emit(AppEvent::Call);@@ -1085,6 +1094,10 @@ impl AppState {1085
if self.call.is_some() {1094
if self.call.is_some() {1086
return;1095
return;1087
}1096
}1097
if let Some(cause) = scene.end_cause() {1098
self.demo_call_end(cause, cx);1099
return;1100
}1088
let (script, model, conversation_id) = if scene.is_one_to_one() {1101
let (script, model, conversation_id) = if scene.is_one_to_one() {1089
(1102
(1090
DemoCall::People(vec![demo_caller()]),1103
DemoCall::People(vec![demo_caller()]),@@ -1359,6 +1372,7 @@ mod tests {1359
use crate::call::background::BackgroundPick;1372
use crate::call::background::BackgroundPick;1360
use crate::call::{CaptionPosition, CaptionSize, RecordAction, ViewSettings};1373
use crate::call::{CaptionPosition, CaptionSize, RecordAction, ViewSettings};1361
use crate::call::demo::demo_ring;1374
use crate::call::demo::demo_ring;1375
use crate::call::end_screen::EndTone;1362
use crate::call::features::room_closed_move;1376
use crate::call::features::room_closed_move;1363
use crate::call::model::BreakoutState;1377
use crate::call::model::BreakoutState;1364
use crate::data::Person;1378
use crate::data::Person;@@ -2343,6 +2357,44 @@ mod tests {2343
});2357
});2344
}2358
}2345
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::CallEndTone(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![EndTone::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
2346
#[gpui_kit::test]2398
#[gpui_kit::test]2347
fn full_window_exists_only_while_someone_shares_and_escape_leaves_it(cx: &mut TestAppContext) {2399
fn full_window_exists_only_while_someone_shares_and_escape_leaves_it(cx: &mut TestAppContext) {2348
let app = app_with_call(cx);2400
let app = app_with_call(cx);@@ -0,0 +1,76 @@
1
use gpui_kit::*;
2
3
use super::end_screen::{CallEndScreen, EndCause};
4
use super::model::{CallKind, PendingMove};
5
use crate::app_state::{AppEvent, AppState};
6
7
const DEMO_MEETING_THREAD: &str = "demo-chat-meeting-standup";
8
9
impl AppState {
10
pub fn dismiss_call_end(&mut self, cx: &mut Context<Self>) {
11
if self.call_end.take().is_some() {
12
cx.emit(AppEvent::Call);
13
cx.notify();
14
}
15
}
16
17
pub fn retry_call_end(&mut self, cx: &mut Context<Self>) {
18
let Some(screen) = self.call_end.take() else {
19
return;
20
};
21
cx.emit(AppEvent::Call);
22
cx.notify();
23
match (screen.kind, screen.meeting_target, screen.conversation_id) {
24
(CallKind::Test, _, _) => self.start_test_call(cx),
25
(CallKind::Meeting, Some(target), _) => self.join_moved_call(
26
PendingMove {
27
target,
28
title: screen.title,
29
breakout: None,
30
},
31
cx,
32
),
33
(CallKind::Group, _, Some(conversation_id))
34
if self.running_meeting(&conversation_id).is_some() =>
35
{
36
self.join_meeting_call(&conversation_id, cx)
37
}
38
(CallKind::Direct | CallKind::Group, _, Some(conversation_id)) => {
39
self.start_chat_call(&conversation_id, cx)
40
}
41
_ => {}
42
}
43
}
44
45
pub fn demo_call_end(&mut self, cause: EndCause, cx: &mut Context<Self>) {
46
let screen = match cause {
47
EndCause::Removed => CallEndScreen {
48
cause,
49
kind: CallKind::Meeting,
50
title: "Standup".to_owned(),
51
conversation_id: Some(DEMO_MEETING_THREAD.to_owned()),
52
meeting_target: Some(calling::MeetingTarget {
53
thread_id: DEMO_MEETING_THREAD.to_owned(),
54
tenant_id: "demo-tenant".to_owned(),
55
organizer_id: "demo-me".to_owned(),
56
meeting_data: None,
57
}),
58
peer: None,
59
},
60
EndCause::Dropped => CallEndScreen {
61
cause,
62
kind: CallKind::Direct,
63
title: "Mara Lindqvist".to_owned(),
64
conversation_id: Some("demo-chat-mara".to_owned()),
65
meeting_target: None,
66
peer: Some(super::end_screen::EndPeer {
67
user_id: Some("demo-mara".to_owned()),
68
name: "Mara Lindqvist".to_owned(),
69
}),
70
},
71
};
72
self.call_end = Some(screen);
73
cx.emit(AppEvent::Call);
74
cx.notify();
75
}
76
}
@@ -0,0 +1,76 @@1
use gpui_kit::*;2
3
use super::end_screen::{CallEndScreen, EndCause};4
use super::model::{CallKind, PendingMove};5
use crate::app_state::{AppEvent, AppState};6
7
const DEMO_MEETING_THREAD: &str = "demo-chat-meeting-standup";8
9
impl AppState {10
pub fn dismiss_call_end(&mut self, cx: &mut Context<Self>) {11
if self.call_end.take().is_some() {12
cx.emit(AppEvent::Call);13
cx.notify();14
}15
}16
17
pub fn retry_call_end(&mut self, cx: &mut Context<Self>) {18
let Some(screen) = self.call_end.take() else {19
return;20
};21
cx.emit(AppEvent::Call);22
cx.notify();23
match (screen.kind, screen.meeting_target, screen.conversation_id) {24
(CallKind::Test, _, _) => self.start_test_call(cx),25
(CallKind::Meeting, Some(target), _) => self.join_moved_call(26
PendingMove {27
target,28
title: screen.title,29
breakout: None,30
},31
cx,32
),33
(CallKind::Group, _, Some(conversation_id))34
if self.running_meeting(&conversation_id).is_some() =>35
{36
self.join_meeting_call(&conversation_id, cx)37
}38
(CallKind::Direct | CallKind::Group, _, Some(conversation_id)) => {39
self.start_chat_call(&conversation_id, cx)40
}41
_ => {}42
}43
}44
45
pub fn demo_call_end(&mut self, cause: EndCause, cx: &mut Context<Self>) {46
let screen = match cause {47
EndCause::Removed => CallEndScreen {48
cause,49
kind: CallKind::Meeting,50
title: "Standup".to_owned(),51
conversation_id: Some(DEMO_MEETING_THREAD.to_owned()),52
meeting_target: Some(calling::MeetingTarget {53
thread_id: DEMO_MEETING_THREAD.to_owned(),54
tenant_id: "demo-tenant".to_owned(),55
organizer_id: "demo-me".to_owned(),56
meeting_data: None,57
}),58
peer: None,59
},60
EndCause::Dropped => CallEndScreen {61
cause,62
kind: CallKind::Direct,63
title: "Mara Lindqvist".to_owned(),64
conversation_id: Some("demo-chat-mara".to_owned()),65
meeting_target: None,66
peer: Some(super::end_screen::EndPeer {67
user_id: Some("demo-mara".to_owned()),68
name: "Mara Lindqvist".to_owned(),69
}),70
},71
};72
self.call_end = Some(screen);73
cx.emit(AppEvent::Call);74
cx.notify();75
}76
}@@ -1,6 +1,7 @@
1
1
pub mod actions;
2
2
pub mod calendar;
3
3
pub mod consult;
4
pub mod end_actions;
4
5
pub mod features;
5
6
pub mod history;
6
7
pub mod join;
@@ -17,7 +18,7 @@ pub mod target;
17
18
pub mod view_actions;
18
19
19
20
pub use app_call_model::{
20
agenda, background, bubbles, caption_style, demo, fullscreen, health, media, mic,
21
agenda, background, bubbles, caption_style, demo, end_screen, fullscreen, health, media, mic,
21
22
model, options_dialog, people, preview, record_rights,
22
23
recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,
23
24
};
@@ -1,6 +1,7 @@1
pub mod actions;1
pub mod actions;2
pub mod calendar;2
pub mod calendar;3
pub mod consult;3
pub mod consult;4
pub mod end_actions;4
pub mod features;5
pub mod features;5
pub mod history;6
pub mod history;6
pub mod join;7
pub mod join;@@ -17,7 +18,7 @@ pub mod target;17
pub mod view_actions;18
pub mod view_actions;18
19
19
pub use app_call_model::{20
pub use app_call_model::{20
agenda, background, bubbles, caption_style, demo, fullscreen, health, media, mic,21
agenda, background, bubbles, caption_style, demo, end_screen, fullscreen, health, media, mic,21
model, options_dialog, people, preview, record_rights,22
model, options_dialog, people, preview, record_rights,22
recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,23
recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,23
};24
};@@ -111,6 +111,7 @@ impl AppState {
111
111
return;
112
112
}
113
113
self.prejoin_count += 1;
114
self.call_end = None;
114
115
self.prejoin = Some(PendingJoin {
115
116
id: self.prejoin_count,
116
117
join,
@@ -111,6 +111,7 @@ impl AppState {111
return;111
return;112
}112
}113
self.prejoin_count += 1;113
self.prejoin_count += 1;114
self.call_end = None;114
self.prejoin = Some(PendingJoin {115
self.prejoin = Some(PendingJoin {115
id: self.prejoin_count,116
id: self.prejoin_count,116
join,117
join,@@ -5,7 +5,7 @@ pub mod settings;
5
5
pub mod stack;
6
6
pub mod text;
7
7
8
pub use app_base::notify::{badge, platform, ring_tone};
8
pub use app_base::notify::{badge, platform, ring_tone, sound_cache};
9
9
pub use incoming::{IncomingTracker, LateArrivals, preview_of};
10
10
#[cfg(windows)]
11
11
pub use platform::native_handle;
@@ -5,7 +5,7 @@ pub mod settings;5
pub mod stack;5
pub mod stack;6
pub mod text;6
pub mod text;7
7
8
pub use app_base::notify::{badge, platform, ring_tone};8
pub use app_base::notify::{badge, platform, ring_tone, sound_cache};9
pub use incoming::{IncomingTracker, LateArrivals, preview_of};9
pub use incoming::{IncomingTracker, LateArrivals, preview_of};10
#[cfg(windows)]10
#[cfg(windows)]11
pub use platform::native_handle;11
pub use platform::native_handle;@@ -16,6 +16,7 @@ use super::rules::{
16
16
should_flash, should_ringback,
17
17
};
18
18
use super::settings;
19
use super::sound_cache;
19
20
use super::settings_view::{Section, SettingsView};
20
21
use super::stack::{
21
22
AgentToast, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE, ToastModel, ToastStack,
@@ -25,6 +26,7 @@ use super::toast::{PillView, ToastView};
25
26
use crate::agents::{AgentRun, AgentRunsEvent, RunState};
26
27
use crate::app_state::{AppEvent, AppState, selection_for};
27
28
use crate::call::DemoScene;
29
use crate::call::end_screen::EndTone;
28
30
use crate::data::{self, Directory, PresenceKind};
29
31
use crate::runtime;
30
32
use crate::single_instance;
@@ -145,6 +147,10 @@ impl NotificationCenter {
145
147
}
146
148
})
147
149
.detach();
150
if !center.demo_mode {
151
let end_tones = EndTone::ALL.map(EndTone::file_name);
152
sound_cache::prefetch(&end_tones, cx);
153
}
148
154
if center.app.read(cx).mode.demo {
149
155
if demo_scene().is_none() {
150
156
cx.spawn(async move |this, cx| {
@@ -248,6 +254,7 @@ impl NotificationCenter {
248
254
AppEvent::Ring => self.on_rings_changed(cx),
249
255
AppEvent::MeetingReminder => self.on_meeting_reminder(cx),
250
256
AppEvent::MeetingChime => self.on_meeting_chime(cx),
257
AppEvent::CallEndTone(tone) => self.on_call_end_tone(*tone, cx),
251
258
AppEvent::Call => self.sync_ringback(cx),
252
259
_ => {}
253
260
}
@@ -573,6 +580,12 @@ impl NotificationCenter {
573
580
}
574
581
}
575
582
583
fn on_call_end_tone(&mut self, tone: EndTone, cx: &mut Context<Self>) {
584
if !self.demo_mode {
585
sound_cache::play(tone.file_name(), cx);
586
}
587
}
588
576
589
pub fn join_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
577
590
self.raise_main_window(cx);
578
591
self.app
@@ -16,6 +16,7 @@ use super::rules::{16
should_flash, should_ringback,16
should_flash, should_ringback,17
};17
};18
use super::settings;18
use super::settings;19
use super::sound_cache;19
use super::settings_view::{Section, SettingsView};20
use super::settings_view::{Section, SettingsView};20
use super::stack::{21
use super::stack::{21
AgentToast, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE, ToastModel, ToastStack,22
AgentToast, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE, ToastModel, ToastStack,@@ -25,6 +26,7 @@ use super::toast::{PillView, ToastView};25
use crate::agents::{AgentRun, AgentRunsEvent, RunState};26
use crate::agents::{AgentRun, AgentRunsEvent, RunState};26
use crate::app_state::{AppEvent, AppState, selection_for};27
use crate::app_state::{AppEvent, AppState, selection_for};27
use crate::call::DemoScene;28
use crate::call::DemoScene;29
use crate::call::end_screen::EndTone;28
use crate::data::{self, Directory, PresenceKind};30
use crate::data::{self, Directory, PresenceKind};29
use crate::runtime;31
use crate::runtime;30
use crate::single_instance;32
use crate::single_instance;@@ -145,6 +147,10 @@ impl NotificationCenter {145
}147
}146
})148
})147
.detach();149
.detach();150
if !center.demo_mode {151
let end_tones = EndTone::ALL.map(EndTone::file_name);152
sound_cache::prefetch(&end_tones, cx);153
}148
if center.app.read(cx).mode.demo {154
if center.app.read(cx).mode.demo {149
if demo_scene().is_none() {155
if demo_scene().is_none() {150
cx.spawn(async move |this, cx| {156
cx.spawn(async move |this, cx| {@@ -248,6 +254,7 @@ impl NotificationCenter {248
AppEvent::Ring => self.on_rings_changed(cx),254
AppEvent::Ring => self.on_rings_changed(cx),249
AppEvent::MeetingReminder => self.on_meeting_reminder(cx),255
AppEvent::MeetingReminder => self.on_meeting_reminder(cx),250
AppEvent::MeetingChime => self.on_meeting_chime(cx),256
AppEvent::MeetingChime => self.on_meeting_chime(cx),257
AppEvent::CallEndTone(tone) => self.on_call_end_tone(*tone, cx),251
AppEvent::Call => self.sync_ringback(cx),258
AppEvent::Call => self.sync_ringback(cx),252
_ => {}259
_ => {}253
}260
}@@ -573,6 +580,12 @@ impl NotificationCenter {573
}580
}574
}581
}575
582
583
fn on_call_end_tone(&mut self, tone: EndTone, cx: &mut Context<Self>) {584
if !self.demo_mode {585
sound_cache::play(tone.file_name(), cx);586
}587
}588
576
pub fn join_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {589
pub fn join_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {577
self.raise_main_window(cx);590
self.raise_main_window(cx);578
self.app591
self.app@@ -0,0 +1,115 @@
1
use gpui_kit::assets::IconName;
2
use gpui_kit::component::button::{Button, ButtonVariants as _};
3
use gpui_kit::component::{h_flex, v_flex};
4
use gpui_kit::prelude::FluentBuilder as _;
5
use gpui_kit::*;
6
7
use super::avatar::person_avatar;
8
use super::widgets::icon;
9
use crate::app_state::AppState;
10
use crate::call::end_screen::{CallEndScreen, DISMISS_LABEL};
11
use crate::theme;
12
13
const CONTENT_WIDTH: f32 = 400.;
14
const AVATAR_SIZE: f32 = 96.;
15
const ICON_SIZE: f32 = 40.;
16
const PANE_PADDING: f32 = 12.;
17
const SECTION_GAP: f32 = 16.;
18
const TEXT_GAP: f32 = 8.;
19
const BUTTON_GAP: f32 = 8.;
20
21
pub fn render_call_end(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> {
22
let screen = state.call_end.as_ref()?;
23
let dismiss_app = app.clone();
24
let retry_app = app.clone();
25
let actions = h_flex()
26
.debug_selector(|| "shell/islands/main/call-end/actions".into())
27
.flex_none()
28
.gap(px(BUTTON_GAP))
29
.justify_center()
30
.child(
31
Button::new("call-end-dismiss")
32
.outline()
33
.label(DISMISS_LABEL)
34
.on_click(move |_, _, cx| {
35
dismiss_app.update(cx, |state, cx| state.dismiss_call_end(cx))
36
}),
37
)
38
.when(screen.can_retry(), |row| {
39
row.child(
40
Button::new("call-end-retry")
41
.primary()
42
.label(screen.retry_label())
43
.on_click(move |_, _, cx| {
44
retry_app.update(cx, |state, cx| state.retry_call_end(cx))
45
}),
46
)
47
});
48
Some(
49
v_flex()
50
.debug_selector(|| "shell/islands/main".into())
51
.flex_1()
52
.min_w_0()
53
.h_full()
54
.p(px(PANE_PADDING))
55
.items_center()
56
.justify_center()
57
.rounded(px(10.))
58
.bg(theme::surface())
59
.overflow_hidden()
60
.child(
61
v_flex()
62
.debug_selector(|| "shell/islands/main/call-end".into())
63
.w(px(CONTENT_WIDTH))
64
.max_w_full()
65
.items_center()
66
.gap(px(SECTION_GAP))
67
.child(badge(state, screen))
68
.child(
69
v_flex()
70
.w_full()
71
.items_center()
72
.gap(px(TEXT_GAP))
73
.child(
74
div()
75
.text_size(px(20.))
76
.font_weight(FontWeight::SEMIBOLD)
77
.text_color(theme::text_strong())
78
.text_center()
79
.child(screen.heading()),
80
)
81
.child(
82
div()
83
.w_full()
84
.text_size(px(14.))
85
.text_color(theme::text_muted())
86
.text_center()
87
.child(screen.description()),
88
),
89
)
90
.child(actions),
91
)
92
.into_any_element(),
93
)
94
}
95
96
fn badge(state: &AppState, screen: &CallEndScreen) -> AnyElement {
97
match &screen.peer {
98
Some(peer) => person_avatar(
99
&state.directory,
100
peer.user_id.as_deref(),
101
&peer.name,
102
AVATAR_SIZE,
103
),
104
None => div()
105
.size(px(AVATAR_SIZE))
106
.flex_none()
107
.rounded_full()
108
.bg(theme::surface_raised())
109
.flex()
110
.items_center()
111
.justify_center()
112
.child(icon(IconName::PhoneOff, ICON_SIZE, theme::text_muted()))
113
.into_any_element(),
114
}
115
}
@@ -0,0 +1,115 @@1
use gpui_kit::assets::IconName;2
use gpui_kit::component::button::{Button, ButtonVariants as _};3
use gpui_kit::component::{h_flex, v_flex};4
use gpui_kit::prelude::FluentBuilder as _;5
use gpui_kit::*;6
7
use super::avatar::person_avatar;8
use super::widgets::icon;9
use crate::app_state::AppState;10
use crate::call::end_screen::{CallEndScreen, DISMISS_LABEL};11
use crate::theme;12
13
const CONTENT_WIDTH: f32 = 400.;14
const AVATAR_SIZE: f32 = 96.;15
const ICON_SIZE: f32 = 40.;16
const PANE_PADDING: f32 = 12.;17
const SECTION_GAP: f32 = 16.;18
const TEXT_GAP: f32 = 8.;19
const BUTTON_GAP: f32 = 8.;20
21
pub fn render_call_end(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> {22
let screen = state.call_end.as_ref()?;23
let dismiss_app = app.clone();24
let retry_app = app.clone();25
let actions = h_flex()26
.debug_selector(|| "shell/islands/main/call-end/actions".into())27
.flex_none()28
.gap(px(BUTTON_GAP))29
.justify_center()30
.child(31
Button::new("call-end-dismiss")32
.outline()33
.label(DISMISS_LABEL)34
.on_click(move |_, _, cx| {35
dismiss_app.update(cx, |state, cx| state.dismiss_call_end(cx))36
}),37
)38
.when(screen.can_retry(), |row| {39
row.child(40
Button::new("call-end-retry")41
.primary()42
.label(screen.retry_label())43
.on_click(move |_, _, cx| {44
retry_app.update(cx, |state, cx| state.retry_call_end(cx))45
}),46
)47
});48
Some(49
v_flex()50
.debug_selector(|| "shell/islands/main".into())51
.flex_1()52
.min_w_0()53
.h_full()54
.p(px(PANE_PADDING))55
.items_center()56
.justify_center()57
.rounded(px(10.))58
.bg(theme::surface())59
.overflow_hidden()60
.child(61
v_flex()62
.debug_selector(|| "shell/islands/main/call-end".into())63
.w(px(CONTENT_WIDTH))64
.max_w_full()65
.items_center()66
.gap(px(SECTION_GAP))67
.child(badge(state, screen))68
.child(69
v_flex()70
.w_full()71
.items_center()72
.gap(px(TEXT_GAP))73
.child(74
div()75
.text_size(px(20.))76
.font_weight(FontWeight::SEMIBOLD)77
.text_color(theme::text_strong())78
.text_center()79
.child(screen.heading()),80
)81
.child(82
div()83
.w_full()84
.text_size(px(14.))85
.text_color(theme::text_muted())86
.text_center()87
.child(screen.description()),88
),89
)90
.child(actions),91
)92
.into_any_element(),93
)94
}95
96
fn badge(state: &AppState, screen: &CallEndScreen) -> AnyElement {97
match &screen.peer {98
Some(peer) => person_avatar(99
&state.directory,100
peer.user_id.as_deref(),101
&peer.name,102
AVATAR_SIZE,103
),104
None => div()105
.size(px(AVATAR_SIZE))106
.flex_none()107
.rounded_full()108
.bg(theme::surface_raised())109
.flex()110
.items_center()111
.justify_center()112
.child(icon(IconName::PhoneOff, ICON_SIZE, theme::text_muted()))113
.into_any_element(),114
}115
}@@ -646,6 +646,7 @@ impl ConversationView {
646
646
| AppEvent::MissedCall(_)
647
647
| AppEvent::MeetingReminder
648
648
| AppEvent::MeetingChime
649
| AppEvent::CallEndTone(_)
649
650
| AppEvent::Call => {}
650
651
AppEvent::LiveMeeting => cx.notify(),
651
652
AppEvent::Saved => cx.notify(),
@@ -646,6 +646,7 @@ impl ConversationView {646
| AppEvent::MissedCall(_)646
| AppEvent::MissedCall(_)647
| AppEvent::MeetingReminder647
| AppEvent::MeetingReminder648
| AppEvent::MeetingChime648
| AppEvent::MeetingChime649
| AppEvent::CallEndTone(_)649
| AppEvent::Call => {}650
| AppEvent::Call => {}650
AppEvent::LiveMeeting => cx.notify(),651
AppEvent::LiveMeeting => cx.notify(),651
AppEvent::Saved => cx.notify(),652
AppEvent::Saved => cx.notify(),@@ -6,6 +6,7 @@ pub mod attachments;
6
6
pub mod avatar;
7
7
pub mod call_card;
8
8
pub mod call_control_fold;
9
pub mod call_end_view;
9
10
pub mod call_controls;
10
11
pub mod call_extras;
11
12
pub mod call_health;
@@ -6,6 +6,7 @@ pub mod attachments;6
pub mod avatar;6
pub mod avatar;7
pub mod call_card;7
pub mod call_card;8
pub mod call_control_fold;8
pub mod call_control_fold;9
pub mod call_end_view;9
pub mod call_controls;10
pub mod call_controls;10
pub mod call_extras;11
pub mod call_extras;11
pub mod call_health;12
pub mod call_health;@@ -6,6 +6,7 @@ use gpui_kit::*;
6
6
use super::activity_panel::{ActivityPanel, ActivityPanelEvent};
7
7
use super::call_mini::CallMiniView;
8
8
use super::call_stage::{render_call_overlay, render_stage_overlay};
9
use super::call_end_view::render_call_end;
9
10
use super::call_view::{CHAT_PANEL_WIDTH, OVERLAY_BELOW as CALL_COLUMN_MIN, render_call_view};
10
11
use super::actions::{NewChat, OpenSwitcher, ReplyToHovered, ToggleCallMute};
11
12
use super::conversation::ConversationView;
@@ -811,7 +812,8 @@ impl Render for AppShell {
811
812
- if show_sidebar { SIDEBAR_WIDTH } else { 0. }
812
813
- 2. * ISLAND_GAP;
813
814
let call_view = render_call_view(&self.state, state, chat_panel, call_fullscreen, island_width)
814
.filter(|_| state.viewing_call());
815
.filter(|_| state.viewing_call())
816
.or_else(|| render_call_end(&self.state, state));
815
817
let (call_view, call_overlay) = match call_view {
816
818
Some(view) if call_fullscreen => (None, Some(render_call_overlay(view))),
817
819
view => (view, None),
@@ -6,6 +6,7 @@ use gpui_kit::*;6
use super::activity_panel::{ActivityPanel, ActivityPanelEvent};6
use super::activity_panel::{ActivityPanel, ActivityPanelEvent};7
use super::call_mini::CallMiniView;7
use super::call_mini::CallMiniView;8
use super::call_stage::{render_call_overlay, render_stage_overlay};8
use super::call_stage::{render_call_overlay, render_stage_overlay};9
use super::call_end_view::render_call_end;9
use super::call_view::{CHAT_PANEL_WIDTH, OVERLAY_BELOW as CALL_COLUMN_MIN, render_call_view};10
use super::call_view::{CHAT_PANEL_WIDTH, OVERLAY_BELOW as CALL_COLUMN_MIN, render_call_view};10
use super::actions::{NewChat, OpenSwitcher, ReplyToHovered, ToggleCallMute};11
use super::actions::{NewChat, OpenSwitcher, ReplyToHovered, ToggleCallMute};11
use super::conversation::ConversationView;12
use super::conversation::ConversationView;@@ -811,7 +812,8 @@ impl Render for AppShell {811
- if show_sidebar { SIDEBAR_WIDTH } else { 0. }812
- if show_sidebar { SIDEBAR_WIDTH } else { 0. }812
- 2. * ISLAND_GAP;813
- 2. * ISLAND_GAP;813
let call_view = render_call_view(&self.state, state, chat_panel, call_fullscreen, island_width)814
let call_view = render_call_view(&self.state, state, chat_panel, call_fullscreen, island_width)814
.filter(|_| state.viewing_call());815
.filter(|_| state.viewing_call())816
.or_else(|| render_call_end(&self.state, state));815
let (call_view, call_overlay) = match call_view {817
let (call_view, call_overlay) = match call_view {816
Some(view) if call_fullscreen => (None, Some(render_call_overlay(view))),818
Some(view) if call_fullscreen => (None, Some(render_call_overlay(view))),817
view => (view, None),819
view => (view, None),@@ -9,18 +9,21 @@ pub enum EndKind {
9
9
Forwarded,
10
10
MediaError,
11
11
RoomClosed,
12
Removed,
12
13
Other,
13
14
}
14
15
15
16
const SUB_CODE_DECLINED: i64 = 10603;
16
17
const SUB_CODES_NO_ANSWER: [i64; 2] = [10408, 10486];
17
18
const SUB_CODES_ROOM_CLOSED: [i64; 2] = [4097, 5030];
19
const SUB_CODES_REMOVED: [i64; 2] = [5000, 5300];
18
20
19
21
pub fn classify_end(code: i64, sub_code: i64) -> EndKind {
20
22
if SUB_CODES_ROOM_CLOSED.contains(&sub_code) {
21
23
return EndKind::RoomClosed;
22
24
}
23
25
match code {
26
0 if SUB_CODES_REMOVED.contains(&sub_code) => EndKind::Removed,
24
27
0 => EndKind::Normal,
25
28
487 => EndKind::Cancelled,
26
29
603 => EndKind::Declined,
@@ -59,6 +62,13 @@ mod tests {
59
62
assert_eq!(classify_end(0, 5001), EndKind::Normal);
60
63
}
61
64
65
#[test]
66
fn being_removed_ends_with_its_own_sub_codes() {
67
assert_eq!(classify_end(0, 5000), EndKind::Removed);
68
assert_eq!(classify_end(0, 5300), EndKind::Removed);
69
assert_eq!(classify_end(500, 5000), EndKind::Other);
70
}
71
62
72
#[test]
63
73
fn unknown_codes_fall_back_to_the_sub_code() {
64
74
assert_eq!(classify_end(500, 10603), EndKind::Declined);
@@ -9,18 +9,21 @@ pub enum EndKind {9
Forwarded,9
Forwarded,10
MediaError,10
MediaError,11
RoomClosed,11
RoomClosed,12
Removed,12
Other,13
Other,13
}14
}14
15
15
const SUB_CODE_DECLINED: i64 = 10603;16
const SUB_CODE_DECLINED: i64 = 10603;16
const SUB_CODES_NO_ANSWER: [i64; 2] = [10408, 10486];17
const SUB_CODES_NO_ANSWER: [i64; 2] = [10408, 10486];17
const SUB_CODES_ROOM_CLOSED: [i64; 2] = [4097, 5030];18
const SUB_CODES_ROOM_CLOSED: [i64; 2] = [4097, 5030];19
const SUB_CODES_REMOVED: [i64; 2] = [5000, 5300];18
20
19
pub fn classify_end(code: i64, sub_code: i64) -> EndKind {21
pub fn classify_end(code: i64, sub_code: i64) -> EndKind {20
if SUB_CODES_ROOM_CLOSED.contains(&sub_code) {22
if SUB_CODES_ROOM_CLOSED.contains(&sub_code) {21
return EndKind::RoomClosed;23
return EndKind::RoomClosed;22
}24
}23
match code {25
match code {26
0 if SUB_CODES_REMOVED.contains(&sub_code) => EndKind::Removed,24
0 => EndKind::Normal,27
0 => EndKind::Normal,25
487 => EndKind::Cancelled,28
487 => EndKind::Cancelled,26
603 => EndKind::Declined,29
603 => EndKind::Declined,@@ -59,6 +62,13 @@ mod tests {59
assert_eq!(classify_end(0, 5001), EndKind::Normal);62
assert_eq!(classify_end(0, 5001), EndKind::Normal);60
}63
}61
64
65
#[test]66
fn being_removed_ends_with_its_own_sub_codes() {67
assert_eq!(classify_end(0, 5000), EndKind::Removed);68
assert_eq!(classify_end(0, 5300), EndKind::Removed);69
assert_eq!(classify_end(500, 5000), EndKind::Other);70
}71
62
#[test]72
#[test]63
fn unknown_codes_fall_back_to_the_sub_code() {73
fn unknown_codes_fall_back_to_the_sub_code() {64
assert_eq!(classify_end(500, 10603), EndKind::Declined);74
assert_eq!(classify_end(500, 10603), EndKind::Declined);