BlueGit

ict rusty-teams

feat(calendar): snooze meeting reminders until the meeting starts

- Snooze hides the toast until the start or until the meeting goes live
- Corner X dismisses the reminder for this meeting only
- Live phase ("live now", green dot) from live-meeting state polled every 30 s in the reminder window
- One generated chime per meeting at the start or first join; quiet with sound off, DND or in a call
- Ported from wip 07fd3b0 onto the app-state / app-base crate split

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-16 · 6 weeks ago

Hash
3a26cce48e67dc8309b75e839f91acfa8159a746
Parent
7cb4a767
11 files changed +430 −60
ROADMAP.md +1 −1
@@ -194,7 +194,7 @@ Feature parity with the Microsoft Teams desktop client.
194 194 | In a call shown in presence | Done | "In a call", "In a meeting", "Presenting" from Teams activity on profile cards and chat headers; no notification sounds during a native call |
195 195 | Schedule a meeting | Partial | Calls tab "New meeting": title, people chips, date, start, end (next half hour, 30 min), Repeat (does not repeat, daily, weekdays, weekly), details, Teams meeting always on. Graph `POST /me/events` with `isOnlineMeeting` and `teamsForBusiness`, local wall time in the own mailbox time zone (series keep their time across DST, weekday from the local date). Body building unit tested; never run against a real calendar |
196 196 | Answer meeting invitations | Partial | Upcoming rows of invited meetings show Accepted / Tentative / Declined / Respond as a menu with "Send a response" (default on); own meetings say Organizer. Graph `accept`, `tentativelyAccept`, `decline`, falls back to the iCalUId lookup when the Teams id is not a Graph id. Not run against a real invitation |
197 | Meeting start reminder | Partial | Toast 5 min before and at the start of an Upcoming meeting: title, time, Join, Dismiss; Ctrl+Shift+J joins from the latest. Quiet during Do not disturb and while in a call. Driven by the polled calendar; push event 128 not wired (the realtime layer does not receive it) |
197 | Meeting start reminder | Partial | Toast 5 min before the start of an Upcoming meeting: title, time, Join, Snooze (back at the start or first join). Corner X dismisses for good. Live state (green dot) from polled live-meeting state. One chime at the start or first join; quiet with sound off and during Do not disturb or a call. Ctrl+Shift+J joins from the latest. Driven by the polled calendar; push event 128 not wired (the realtime layer does not receive it) |
198 198 | Pre-join screen | Partial | Join from Upcoming, chat, Join with ID, link or reminder opens a screen in the chat pane: camera preview, camera and mic switches, background menu, camera, microphone and speaker selects, "Computer audio" or "Don't use audio" (audio off in both directions), Join now, Cancel. Camera, mic and devices remembered. 1:1 calls and Meet now skip it. Checked in the demo only |
199 199 | Narrow windows in a call | Done | Controls that do not fit move into "..." (View, Reactions, Raise hand, People, Chat; mic, camera, share, "..." and Leave always stay). Below 960 px, or when a side panel would leave the call under 720 px, the chat list hides; still too narrow, the panel overlays the call. Layout guard checks 640x480, 1280x800, 1920x1080 |
200 200 | Give and take control | Missing | Protocol known (main-channel data channel, action codes 0-11); needs a second person and a security review |
@@ -194,7 +194,7 @@ Feature parity with the Microsoft Teams desktop client.
194| In a call shown in presence | Done | "In a call", "In a meeting", "Presenting" from Teams activity on profile cards and chat headers; no notification sounds during a native call |
194| In a call shown in presence | Done | "In a call", "In a meeting", "Presenting" from Teams activity on profile cards and chat headers; no notification sounds during a native call |
195| Schedule a meeting | Partial | Calls tab "New meeting": title, people chips, date, start, end (next half hour, 30 min), Repeat (does not repeat, daily, weekdays, weekly), details, Teams meeting always on. Graph `POST /me/events` with `isOnlineMeeting` and `teamsForBusiness`, local wall time in the own mailbox time zone (series keep their time across DST, weekday from the local date). Body building unit tested; never run against a real calendar |
195| Schedule a meeting | Partial | Calls tab "New meeting": title, people chips, date, start, end (next half hour, 30 min), Repeat (does not repeat, daily, weekdays, weekly), details, Teams meeting always on. Graph `POST /me/events` with `isOnlineMeeting` and `teamsForBusiness`, local wall time in the own mailbox time zone (series keep their time across DST, weekday from the local date). Body building unit tested; never run against a real calendar |
196| Answer meeting invitations | Partial | Upcoming rows of invited meetings show Accepted / Tentative / Declined / Respond as a menu with "Send a response" (default on); own meetings say Organizer. Graph `accept`, `tentativelyAccept`, `decline`, falls back to the iCalUId lookup when the Teams id is not a Graph id. Not run against a real invitation |
196| Answer meeting invitations | Partial | Upcoming rows of invited meetings show Accepted / Tentative / Declined / Respond as a menu with "Send a response" (default on); own meetings say Organizer. Graph `accept`, `tentativelyAccept`, `decline`, falls back to the iCalUId lookup when the Teams id is not a Graph id. Not run against a real invitation |
197| Meeting start reminder | Partial | Toast 5 min before and at the start of an Upcoming meeting: title, time, Join, Dismiss; Ctrl+Shift+J joins from the latest. Quiet during Do not disturb and while in a call. Driven by the polled calendar; push event 128 not wired (the realtime layer does not receive it) |
197| Meeting start reminder | Partial | Toast 5 min before the start of an Upcoming meeting: title, time, Join, Snooze (back at the start or first join). Corner X dismisses for good. Live state (green dot) from polled live-meeting state. One chime at the start or first join; quiet with sound off and during Do not disturb or a call. Ctrl+Shift+J joins from the latest. Driven by the polled calendar; push event 128 not wired (the realtime layer does not receive it) |
198| Pre-join screen | Partial | Join from Upcoming, chat, Join with ID, link or reminder opens a screen in the chat pane: camera preview, camera and mic switches, background menu, camera, microphone and speaker selects, "Computer audio" or "Don't use audio" (audio off in both directions), Join now, Cancel. Camera, mic and devices remembered. 1:1 calls and Meet now skip it. Checked in the demo only |
198| Pre-join screen | Partial | Join from Upcoming, chat, Join with ID, link or reminder opens a screen in the chat pane: camera preview, camera and mic switches, background menu, camera, microphone and speaker selects, "Computer audio" or "Don't use audio" (audio off in both directions), Join now, Cancel. Camera, mic and devices remembered. 1:1 calls and Meet now skip it. Checked in the demo only |
199| Narrow windows in a call | Done | Controls that do not fit move into "..." (View, Reactions, Raise hand, People, Chat; mic, camera, share, "..." and Leave always stay). Below 960 px, or when a side panel would leave the call under 720 px, the chat list hides; still too narrow, the panel overlays the call. Layout guard checks 640x480, 1280x800, 1920x1080 |
199| Narrow windows in a call | Done | Controls that do not fit move into "..." (View, Reactions, Raise hand, People, Chat; mic, camera, share, "..." and Leave always stay). Below 960 px, or when a side panel would leave the call under 720 px, the chat list hides; still too narrow, the panel overlays the call. Layout guard checks 640x480, 1280x800, 1920x1080 |
200| Give and take control | Missing | Protocol known (main-channel data channel, action codes 0-11); needs a second person and a security review |
200| Give and take control | Missing | Protocol known (main-channel data channel, action codes 0-11); needs a second person and a security review |
crates/app-base/src/notify/platform/stub.rs +2 −0
@@ -80,6 +80,8 @@ pub fn start_ringback() -> Option<RingTone> {
80 80
81 81 pub fn play_preview(_ringtone: Ringtone) {}
82 82
83 pub fn play_meeting_chime() {}
84
83 85 pub struct Tray;
84 86
85 87 impl Tray {
@@ -80,6 +80,8 @@ pub fn start_ringback() -> Option<RingTone> {
80
80
81pub fn play_preview(_ringtone: Ringtone) {}
81pub fn play_preview(_ringtone: Ringtone) {}
82
82
83pub fn play_meeting_chime() {}
84
83pub struct Tray;
85pub struct Tray;
84
86
85impl Tray {
87impl Tray {
crates/app-base/src/notify/platform/windows_impl.rs +9 −2
@@ -43,7 +43,7 @@ use windows::core::{BOOL, PCWSTR, w};
43 43 use super::stack_plan::{StackPlan, stack_plan};
44 44 use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, WorkArea};
45 45 use crate::notify::badge::{BADGE_SIZE, Badge, render_badge};
46 use crate::notify::ring_tone::{Ringtone, SAMPLE_RATE, ringback_cycle};
46 use crate::notify::ring_tone::{Ringtone, SAMPLE_RATE, meeting_chime, ringback_cycle};
47 47
48 48 const SOUND_BYTES: &[u8] = include_bytes!("../../../../app/assets/sounds/notification.mp3");
49 49 const TRAY_ICON_PNG: &[u8] = include_bytes!("../../../../app/assets/icon/teams-fast-256.png");
@@ -535,7 +535,14 @@ pub fn start_ringback() -> Option<RingTone> {
535 535 }
536 536
537 537 pub fn play_preview(ringtone: Ringtone) {
538 let cycle = ringtone.cycle(SAMPLE_RATE);
538 play_once(ringtone.cycle(SAMPLE_RATE));
539 }
540
541 pub fn play_meeting_chime() {
542 play_once(meeting_chime(SAMPLE_RATE));
543 }
544
545 fn play_once(cycle: Vec<f32>) {
539 546 std::thread::spawn(move || {
540 547 let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {
541 548 return;
@@ -43,7 +43,7 @@ use windows::core::{BOOL, PCWSTR, w};
43use super::stack_plan::{StackPlan, stack_plan};
43use super::stack_plan::{StackPlan, stack_plan};
44use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, WorkArea};
44use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, WorkArea};
45use crate::notify::badge::{BADGE_SIZE, Badge, render_badge};
45use crate::notify::badge::{BADGE_SIZE, Badge, render_badge};
46use crate::notify::ring_tone::{Ringtone, SAMPLE_RATE, ringback_cycle};
46use crate::notify::ring_tone::{Ringtone, SAMPLE_RATE, meeting_chime, ringback_cycle};
47
47
48const SOUND_BYTES: &[u8] = include_bytes!("../../../../app/assets/sounds/notification.mp3");
48const SOUND_BYTES: &[u8] = include_bytes!("../../../../app/assets/sounds/notification.mp3");
49const TRAY_ICON_PNG: &[u8] = include_bytes!("../../../../app/assets/icon/teams-fast-256.png");
49const TRAY_ICON_PNG: &[u8] = include_bytes!("../../../../app/assets/icon/teams-fast-256.png");
@@ -535,7 +535,14 @@ pub fn start_ringback() -> Option<RingTone> {
535}
535}
536
536
537pub fn play_preview(ringtone: Ringtone) {
537pub fn play_preview(ringtone: Ringtone) {
538 let cycle = ringtone.cycle(SAMPLE_RATE);
538 play_once(ringtone.cycle(SAMPLE_RATE));
539}
540
541pub fn play_meeting_chime() {
542 play_once(meeting_chime(SAMPLE_RATE));
543}
544
545fn play_once(cycle: Vec<f32>) {
539 std::thread::spawn(move || {
546 std::thread::spawn(move || {
540 let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {
547 let Ok(mut sink) = rodio::DeviceSinkBuilder::open_default_sink() else {
541 return;
548 return;
crates/app-base/src/notify/ring_tone.rs +19 −0
@@ -14,6 +14,8 @@ const CHIME_CYCLE_SECONDS: f32 = 2.6;
14 14 const PULSE_NOTES: [f32; 3] = [587.33, 587.33, 587.33];
15 15 const PULSE_NOTE_SECONDS: f32 = 0.26;
16 16 const PULSE_CYCLE_SECONDS: f32 = 2.2;
17 const MEETING_NOTES: [f32; 3] = [659.25, 783.99, 1046.5];
18 const MEETING_NOTE_SECONDS: f32 = 0.26;
17 19 const RINGBACK_HZ: f32 = 425.;
18 20 const RINGBACK_ON_SECONDS: f32 = 1.;
19 21 const RINGBACK_CYCLE_SECONDS: f32 = 5.;
@@ -74,6 +76,11 @@ pub fn ring_cycle(sample_rate: u32) -> Vec<f32> {
74 76 tone_cycle(sample_rate, &BEEPS, BEEP_SECONDS, CYCLE_SECONDS)
75 77 }
76 78
79 pub fn meeting_chime(sample_rate: u32) -> Vec<f32> {
80 let seconds = MEETING_NOTE_SECONDS * MEETING_NOTES.len() as f32;
81 tone_cycle(sample_rate, &MEETING_NOTES, MEETING_NOTE_SECONDS, seconds)
82 }
83
77 84 pub fn ringback_cycle(sample_rate: u32) -> Vec<f32> {
78 85 tone_cycle(
79 86 sample_rate,
@@ -182,6 +189,18 @@ mod tests {
182 189 );
183 190 }
184 191
192 #[test]
193 fn the_meeting_chime_is_short_quiet_and_audible() {
194 let samples = meeting_chime(SAMPLE_RATE);
195 assert!(samples.len() <= SAMPLE_RATE as usize);
196 assert!(
197 samples
198 .iter()
199 .all(|sample| sample.abs() <= AMPLITUDE + f32::EPSILON)
200 );
201 assert!(samples.iter().any(|sample| sample.abs() > AMPLITUDE * 0.9));
202 }
203
185 204 #[test]
186 205 fn ringtone_keys_round_trip() {
187 206 for ringtone in Ringtone::ALL {
@@ -14,6 +14,8 @@ const CHIME_CYCLE_SECONDS: f32 = 2.6;
14const PULSE_NOTES: [f32; 3] = [587.33, 587.33, 587.33];
14const PULSE_NOTES: [f32; 3] = [587.33, 587.33, 587.33];
15const PULSE_NOTE_SECONDS: f32 = 0.26;
15const PULSE_NOTE_SECONDS: f32 = 0.26;
16const PULSE_CYCLE_SECONDS: f32 = 2.2;
16const PULSE_CYCLE_SECONDS: f32 = 2.2;
17const MEETING_NOTES: [f32; 3] = [659.25, 783.99, 1046.5];
18const MEETING_NOTE_SECONDS: f32 = 0.26;
17const RINGBACK_HZ: f32 = 425.;
19const RINGBACK_HZ: f32 = 425.;
18const RINGBACK_ON_SECONDS: f32 = 1.;
20const RINGBACK_ON_SECONDS: f32 = 1.;
19const RINGBACK_CYCLE_SECONDS: f32 = 5.;
21const RINGBACK_CYCLE_SECONDS: f32 = 5.;
@@ -74,6 +76,11 @@ pub fn ring_cycle(sample_rate: u32) -> Vec<f32> {
74 tone_cycle(sample_rate, &BEEPS, BEEP_SECONDS, CYCLE_SECONDS)
76 tone_cycle(sample_rate, &BEEPS, BEEP_SECONDS, CYCLE_SECONDS)
75}
77}
76
78
79pub fn meeting_chime(sample_rate: u32) -> Vec<f32> {
80 let seconds = MEETING_NOTE_SECONDS * MEETING_NOTES.len() as f32;
81 tone_cycle(sample_rate, &MEETING_NOTES, MEETING_NOTE_SECONDS, seconds)
82}
83
77pub fn ringback_cycle(sample_rate: u32) -> Vec<f32> {
84pub fn ringback_cycle(sample_rate: u32) -> Vec<f32> {
78 tone_cycle(
85 tone_cycle(
79 sample_rate,
86 sample_rate,
@@ -182,6 +189,18 @@ mod tests {
182 );
189 );
183 }
190 }
184
191
192 #[test]
193 fn the_meeting_chime_is_short_quiet_and_audible() {
194 let samples = meeting_chime(SAMPLE_RATE);
195 assert!(samples.len() <= SAMPLE_RATE as usize);
196 assert!(
197 samples
198 .iter()
199 .all(|sample| sample.abs() <= AMPLITUDE + f32::EPSILON)
200 );
201 assert!(samples.iter().any(|sample| sample.abs() > AMPLITUDE * 0.9));
202 }
203
185 #[test]
204 #[test]
186 fn ringtone_keys_round_trip() {
205 fn ringtone_keys_round_trip() {
187 for ringtone in Ringtone::ALL {
206 for ringtone in Ringtone::ALL {
crates/app-state/src/app_state.rs +1 −0
@@ -69,6 +69,7 @@ pub enum AppEvent {
69 69 LiveMeeting,
70 70 MissedCall(MissedCall),
71 71 MeetingReminder,
72 MeetingChime,
72 73 }
73 74
74 75 #[derive(Debug, Clone, Copy, Default)]
@@ -69,6 +69,7 @@ pub enum AppEvent {
69 LiveMeeting,
69 LiveMeeting,
70 MissedCall(MissedCall),
70 MissedCall(MissedCall),
71 MeetingReminder,
71 MeetingReminder,
72 MeetingChime,
72}
73}
73
74
74#[derive(Debug, Clone, Copy, Default)]
75#[derive(Debug, Clone, Copy, Default)]
crates/app-state/src/call/actions.rs +7 −1
@@ -1283,7 +1283,13 @@ impl AppState {
1283 1283 }
1284 1284
1285 1285 pub fn refresh_live_meeting(&mut self, conversation_id: &str, cx: &mut Context<Self>) {
1286 if self.mode.demo || !self.watches_live_meeting(conversation_id) {
1286 if self.watches_live_meeting(conversation_id) {
1287 self.fetch_live_meeting(conversation_id, cx);
1288 }
1289 }
1290
1291 pub fn fetch_live_meeting(&mut self, conversation_id: &str, cx: &mut Context<Self>) {
1292 if self.mode.demo {
1287 1293 return;
1288 1294 }
1289 1295 let Some(launcher) = self.call_launcher.clone() else {
@@ -1283,7 +1283,13 @@ impl AppState {
1283 }
1283 }
1284
1284
1285 pub fn refresh_live_meeting(&mut self, conversation_id: &str, cx: &mut Context<Self>) {
1285 pub fn refresh_live_meeting(&mut self, conversation_id: &str, cx: &mut Context<Self>) {
1286 if self.mode.demo || !self.watches_live_meeting(conversation_id) {
1286 if self.watches_live_meeting(conversation_id) {
1287 self.fetch_live_meeting(conversation_id, cx);
1288 }
1289 }
1290
1291 pub fn fetch_live_meeting(&mut self, conversation_id: &str, cx: &mut Context<Self>) {
1292 if self.mode.demo {
1287 return;
1293 return;
1288 }
1294 }
1289 let Some(launcher) = self.call_launcher.clone() else {
1295 let Some(launcher) = self.call_launcher.clone() else {
crates/app-state/src/call/mod.rs +1 −1
@@ -52,7 +52,7 @@ pub use people::{PeopleSections, PersonRow, people_sections};
52 52 pub use share_actions::ZoomStep;
53 53 pub use share_view::{SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY, STRIP_DEFAULT_WIDTH, ShareStage, load_flag, load_strip_width};
54 54 pub use preview::{CameraPreview, preview_backgrounds};
55 pub use reminder::{MeetingToasts, subtitle as meeting_subtitle};
55 pub use reminder::{MeetingToasts, ReminderPhase, subtitle as meeting_subtitle};
56 56 pub use ring::{MissedCall, RingEntry, Rings};
57 57 pub use stage_split::{
58 58 GRID_PADDING, STRIP_GAP, SpeakerSplit, StripSplit, TILE_GAP, gallery_split,
@@ -52,7 +52,7 @@ pub use people::{PeopleSections, PersonRow, people_sections};
52pub use share_actions::ZoomStep;
52pub use share_actions::ZoomStep;
53pub use share_view::{SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY, STRIP_DEFAULT_WIDTH, ShareStage, load_flag, load_strip_width};
53pub use share_view::{SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY, STRIP_DEFAULT_WIDTH, ShareStage, load_flag, load_strip_width};
54pub use preview::{CameraPreview, preview_backgrounds};
54pub use preview::{CameraPreview, preview_backgrounds};
55pub use reminder::{MeetingToasts, subtitle as meeting_subtitle};
55pub use reminder::{MeetingToasts, ReminderPhase, subtitle as meeting_subtitle};
56pub use ring::{MissedCall, RingEntry, Rings};
56pub use ring::{MissedCall, RingEntry, Rings};
57pub use stage_split::{
57pub use stage_split::{
58 GRID_PADDING, STRIP_GAP, SpeakerSplit, StripSplit, TILE_GAP, gallery_split,
58 GRID_PADDING, STRIP_GAP, SpeakerSplit, StripSplit, TILE_GAP, gallery_split,
crates/app-state/src/call/reminder.rs +331 −47
@@ -9,11 +9,13 @@ use crate::app_state::{AppEvent, AppState};
9 9 pub const LEAD_MINUTES: i64 = 5;
10 10 pub const GRACE_MINUTES: i64 = 5;
11 11 const CHECK_EVERY_SECONDS: i64 = 1;
12 const LIVE_POLL_SECONDS: i64 = 30;
12 13
13 14 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
14 15 pub enum ReminderPhase {
15 16 Soon,
16 17 Started,
18 Live,
17 19 }
18 20
19 21 #[derive(Debug, Clone, PartialEq, Eq)]
@@ -30,7 +32,7 @@ fn event_key(event: &CalendarEvent) -> String {
30 32 format!("{}@{}", event.object_id, event.start.timestamp())
31 33 }
32 34
33 pub fn phase_at(event: &CalendarEvent, now: DateTime<Utc>) -> Option<ReminderPhase> {
35 pub fn phase_at(event: &CalendarEvent, now: DateTime<Utc>, live: bool) -> Option<ReminderPhase> {
34 36 let eligible = event.online
35 37 && !event.cancelled
36 38 && !event.all_day
@@ -39,19 +41,37 @@ pub fn phase_at(event: &CalendarEvent, now: DateTime<Utc>) -> Option<ReminderPha
39 41 if !eligible {
40 42 return None;
41 43 }
42 if now >= event.start - Duration::minutes(LEAD_MINUTES) && now < event.start {
43 return Some(ReminderPhase::Soon);
44 }
44 let opens = event.start - Duration::minutes(LEAD_MINUTES);
45 45 let started_until = event
46 46 .end
47 47 .min(event.start + Duration::minutes(GRACE_MINUTES));
48 if live && now >= opens && now < started_until {
49 return Some(ReminderPhase::Live);
50 }
51 if now >= opens && now < event.start {
52 return Some(ReminderPhase::Soon);
53 }
48 54 (now >= event.start && now < started_until).then_some(ReminderPhase::Started)
49 55 }
50 56
57 fn is_live(event: &CalendarEvent, live_threads: &HashSet<String>) -> bool {
58 event
59 .thread_id
60 .as_ref()
61 .is_some_and(|thread_id| live_threads.contains(thread_id))
62 }
63
64 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
65 pub struct ReminderUpdate {
66 pub changed: bool,
67 pub chime: bool,
68 }
69
51 70 pub fn subtitle(toast: &MeetingToast, now: DateTime<Utc>, offset: FixedOffset) -> String {
52 71 let clock = toast.start.with_timezone(&offset).format("%H:%M");
53 72 match toast.phase {
54 73 ReminderPhase::Started => format!("{clock} - started"),
74 ReminderPhase::Live => format!("{clock} - live now"),
55 75 ReminderPhase::Soon => {
56 76 let minutes = ((toast.start - now).num_seconds().max(0) + 59) / 60;
57 77 match minutes {
@@ -67,8 +87,12 @@ pub fn subtitle(toast: &MeetingToast, now: DateTime<Utc>, offset: FixedOffset) -
67 87 pub struct MeetingToasts {
68 88 entries: Vec<MeetingToast>,
69 89 fired: HashSet<(String, ReminderPhase)>,
90 snoozed: HashSet<String>,
91 dismissed: HashSet<String>,
92 chimed: HashSet<String>,
70 93 next_id: u64,
71 94 last_check: Option<DateTime<Utc>>,
95 last_live_poll: Option<DateTime<Utc>>,
72 96 }
73 97
74 98 impl MeetingToasts {
@@ -90,7 +114,16 @@ impl MeetingToasts {
90 114
91 115 pub fn dismiss(&mut self, id: u64) -> Option<MeetingToast> {
92 116 let index = self.entries.iter().position(|toast| toast.id == id)?;
93 Some(self.entries.remove(index))
117 let toast = self.entries.remove(index);
118 self.dismissed.insert(toast.event_key.clone());
119 Some(toast)
120 }
121
122 pub fn snooze(&mut self, id: u64) -> Option<MeetingToast> {
123 let index = self.entries.iter().position(|toast| toast.id == id)?;
124 let toast = self.entries.remove(index);
125 self.snoozed.insert(toast.event_key.clone());
126 Some(toast)
94 127 }
95 128
96 129 pub fn clear(&mut self) -> bool {
@@ -104,22 +137,75 @@ impl MeetingToasts {
104 137 .is_none_or(|last| now - last >= Duration::seconds(CHECK_EVERY_SECONDS))
105 138 }
106 139
107 pub fn update(&mut self, events: &[CalendarEvent], now: DateTime<Utc>, show: bool) -> bool {
140 pub fn live_candidates(&mut self, events: &[CalendarEvent], now: DateTime<Utc>) -> Vec<String> {
141 let due = self
142 .last_live_poll
143 .is_none_or(|last| now - last >= Duration::seconds(LIVE_POLL_SECONDS));
144 if !due {
145 return Vec::new();
146 }
147 let candidates: Vec<String> = events
148 .iter()
149 .filter(|event| {
150 phase_at(event, now, false).is_some() && !self.dismissed.contains(&event_key(event))
151 })
152 .filter_map(|event| event.thread_id.clone())
153 .collect();
154 if !candidates.is_empty() {
155 self.last_live_poll = Some(now);
156 }
157 candidates
158 }
159
160 pub fn update(
161 &mut self,
162 events: &[CalendarEvent],
163 live_threads: &HashSet<String>,
164 now: DateTime<Utc>,
165 show: bool,
166 ) -> ReminderUpdate {
108 167 self.last_check = Some(now);
109 168 let before = self.entries.clone();
110 169 self.entries.retain(|toast| {
111 events
112 .iter()
113 .any(|event| event_key(event) == toast.event_key && phase_at(event, now).is_some())
170 events.iter().any(|event| {
171 event_key(event) == toast.event_key
172 && phase_at(event, now, is_live(event, live_threads)).is_some()
173 })
114 174 });
115 175 let keys: HashSet<String> = events.iter().map(event_key).collect();
116 176 self.fired.retain(|(key, _)| keys.contains(key));
177 self.snoozed.retain(|key| keys.contains(key));
178 self.dismissed.retain(|key| keys.contains(key));
179 self.chimed.retain(|key| keys.contains(key));
180 let mut chime = false;
117 181 for event in events {
118 let Some(phase) = phase_at(event, now) else {
182 let Some(phase) = phase_at(event, now, is_live(event, live_threads)) else {
119 183 continue;
120 184 };
121 185 let key = event_key(event);
122 if !self.fired.insert((key.clone(), phase)) || !show {
186 if self.dismissed.contains(&key) {
187 continue;
188 }
189 let chime_due = phase != ReminderPhase::Soon && !self.chimed.contains(&key);
190 if let Some(existing) = self.entries.iter_mut().find(|toast| toast.event_key == key) {
191 existing.phase = phase;
192 if chime_due {
193 self.chimed.insert(key);
194 chime |= show;
195 }
196 continue;
197 }
198 if self.snoozed.contains(&key) {
199 if phase == ReminderPhase::Soon {
200 continue;
201 }
202 self.snoozed.remove(&key);
203 } else if self.fired.contains(&(key.clone(), phase)) {
204 continue;
205 }
206 self.fired.insert((key.clone(), phase));
207 if !show {
208 self.chimed.insert(key);
123 209 continue;
124 210 }
125 211 let Some(join_url) = event.join_url.clone() else {
@@ -130,9 +216,9 @@ impl MeetingToasts {
130 216 } else {
131 217 event.subject.clone()
132 218 };
133 if let Some(existing) = self.entries.iter_mut().find(|toast| toast.event_key == key) {
134 existing.phase = phase;
135 continue;
219 if chime_due {
220 self.chimed.insert(key.clone());
221 chime = true;
136 222 }
137 223 self.next_id += 1;
138 224 self.entries.push(MeetingToast {
@@ -144,7 +230,10 @@ impl MeetingToasts {
144 230 join_url,
145 231 });
146 232 }
147 self.entries != before
233 ReminderUpdate {
234 changed: self.entries != before,
235 chime,
236 }
148 237 }
149 238 }
150 239
@@ -153,11 +242,28 @@ impl AppState {
153 242 let now = Utc::now();
154 243 let in_call = self.call.is_some();
155 244 let show = show && !in_call && !self.mode.read_only;
156 let changed = self.meeting_toasts.update(&self.calendar_events, now, show);
157 if (in_call && self.meeting_toasts.clear()) || changed {
245 for thread_id in self
246 .meeting_toasts
247 .live_candidates(&self.calendar_events, now)
248 {
249 self.fetch_live_meeting(&thread_id, cx);
250 }
251 let live_threads: HashSet<String> = self
252 .calendar_events
253 .iter()
254 .filter_map(|event| event.thread_id.clone())
255 .filter(|thread_id| self.running_meeting(thread_id).is_some())
256 .collect();
257 let update = self
258 .meeting_toasts
259 .update(&self.calendar_events, &live_threads, now, show);
260 if (in_call && self.meeting_toasts.clear()) || update.changed {
158 261 cx.emit(AppEvent::MeetingReminder);
159 262 cx.notify();
160 263 }
264 if update.chime {
265 cx.emit(AppEvent::MeetingChime);
266 }
161 267 }
162 268
163 269 pub fn join_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
@@ -177,6 +283,13 @@ impl AppState {
177 283 }
178 284 }
179 285
286 pub fn snooze_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
287 if self.meeting_toasts.snooze(id).is_some() {
288 cx.emit(AppEvent::MeetingReminder);
289 cx.notify();
290 }
291 }
292
180 293 pub fn dismiss_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
181 294 if self.meeting_toasts.dismiss(id).is_some() {
182 295 cx.emit(AppEvent::MeetingReminder);
@@ -214,21 +327,52 @@ mod tests {
214 327 }
215 328 }
216 329
330 fn tick(
331 toasts: &mut MeetingToasts,
332 events: &[CalendarEvent],
333 now: DateTime<Utc>,
334 show: bool,
335 ) -> ReminderUpdate {
336 toasts.update(events, &HashSet::new(), now, show)
337 }
338
339 fn tick_live(
340 toasts: &mut MeetingToasts,
341 events: &[CalendarEvent],
342 now: DateTime<Utc>,
343 ) -> ReminderUpdate {
344 let live_threads = HashSet::from(["thread".to_owned()]);
345 toasts.update(events, &live_threads, now, true)
346 }
347
348 fn live_event(id: &str) -> CalendarEvent {
349 CalendarEvent {
350 thread_id: Some("thread".into()),
351 ..event(id)
352 }
353 }
354
217 355 #[test]
218 356 fn the_phase_follows_the_clock_around_the_start() {
219 357 let meeting = event("a");
220 assert_eq!(phase_at(&meeting, at(8, 54, 59)), None);
221 assert_eq!(phase_at(&meeting, at(8, 55, 0)), Some(ReminderPhase::Soon));
222 assert_eq!(phase_at(&meeting, at(8, 59, 59)), Some(ReminderPhase::Soon));
358 assert_eq!(phase_at(&meeting, at(8, 54, 59), false), None);
359 assert_eq!(
360 phase_at(&meeting, at(8, 55, 0), false),
361 Some(ReminderPhase::Soon)
362 );
363 assert_eq!(
364 phase_at(&meeting, at(8, 59, 59), false),
365 Some(ReminderPhase::Soon)
366 );
223 367 assert_eq!(
224 phase_at(&meeting, at(9, 0, 0)),
368 phase_at(&meeting, at(9, 0, 0), false),
225 369 Some(ReminderPhase::Started)
226 370 );
227 371 assert_eq!(
228 phase_at(&meeting, at(9, 4, 59)),
372 phase_at(&meeting, at(9, 4, 59), false),
229 373 Some(ReminderPhase::Started)
230 374 );
231 assert_eq!(phase_at(&meeting, at(9, 5, 0)), None);
375 assert_eq!(phase_at(&meeting, at(9, 5, 0), false), None);
232 376 }
233 377
234 378 #[test]
@@ -237,8 +381,11 @@ mod tests {
237 381 end: at(9, 3, 0),
238 382 ..event("a")
239 383 };
240 assert_eq!(phase_at(&short, at(9, 2, 59)), Some(ReminderPhase::Started));
241 assert_eq!(phase_at(&short, at(9, 3, 0)), None);
384 assert_eq!(
385 phase_at(&short, at(9, 2, 59), false),
386 Some(ReminderPhase::Started)
387 );
388 assert_eq!(phase_at(&short, at(9, 3, 0), false), None);
242 389 }
243 390
244 391 #[test]
@@ -260,7 +407,7 @@ mod tests {
260 407 ..event("a")
261 408 };
262 409 for quiet in [declined, cancelled, all_day, offline] {
263 assert_eq!(phase_at(&quiet, at(8, 58, 0)), None);
410 assert_eq!(phase_at(&quiet, at(8, 58, 0), false), None);
264 411 }
265 412 }
266 413
@@ -268,39 +415,172 @@ mod tests {
268 415 fn each_phase_fires_once_per_meeting() {
269 416 let events = [event("a")];
270 417 let mut toasts = MeetingToasts::default();
271 assert!(!toasts.update(&events, at(8, 54, 0), true));
272 assert!(toasts.update(&events, at(8, 55, 0), true));
418 assert!(!tick(&mut toasts, &events, at(8, 54, 0), true).changed);
419 assert!(tick(&mut toasts, &events, at(8, 55, 0), true).changed);
273 420 assert_eq!(toasts.entries().len(), 1);
274 421 let id = toasts.entries()[0].id;
275 422 toasts.dismiss(id);
276 assert!(!toasts.update(&events, at(8, 56, 0), true));
423 assert!(!tick(&mut toasts, &events, at(8, 56, 0), true).changed);
277 424 assert!(toasts.is_empty());
278 425 }
279 426
280 427 #[test]
281 fn the_start_brings_a_dismissed_toast_back_and_updates_an_open_one() {
428 fn the_start_moves_an_open_toast_to_started_and_chimes() {
282 429 let events = [event("a")];
283 430 let mut toasts = MeetingToasts::default();
284 toasts.update(&events, at(8, 55, 0), true);
431 assert!(!tick(&mut toasts, &events, at(8, 55, 0), true).chime);
285 432 let id = toasts.entries()[0].id;
286 assert!(toasts.update(&events, at(9, 0, 0), true));
433 let update = tick(&mut toasts, &events, at(9, 0, 0), true);
434 assert!(update.changed && update.chime);
287 435 assert_eq!(toasts.entries().len(), 1);
288 436 assert_eq!(toasts.entries()[0].id, id);
289 437 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Started);
290 let mut dismissed = MeetingToasts::default();
291 dismissed.update(&events, at(8, 55, 0), true);
292 let soon_id = dismissed.entries()[0].id;
293 dismissed.dismiss(soon_id);
294 assert!(dismissed.update(&events, at(9, 0, 0), true));
295 assert_eq!(dismissed.entries()[0].phase, ReminderPhase::Started);
438 assert!(!tick(&mut toasts, &events, at(9, 1, 0), true).chime);
439 }
440
441 #[test]
442 fn a_toast_closed_with_the_corner_x_stays_gone_and_silent() {
443 let events = [event("a")];
444 let mut toasts = MeetingToasts::default();
445 tick(&mut toasts, &events, at(8, 55, 0), true);
446 let id = toasts.entries()[0].id;
447 toasts.dismiss(id);
448 let update = tick(&mut toasts, &events, at(9, 0, 0), true);
449 assert!(!update.changed && !update.chime);
450 assert!(toasts.is_empty());
451 }
452
453 #[test]
454 fn the_corner_x_only_closes_its_own_meeting() {
455 let events = [event("a"), event("b")];
456 let mut toasts = MeetingToasts::default();
457 tick(&mut toasts, &events, at(8, 55, 0), true);
458 let first = toasts.entries()[0].id;
459 toasts.dismiss(first);
460 let update = tick(&mut toasts, &events, at(9, 0, 0), true);
461 assert!(update.chime);
462 assert_eq!(toasts.entries().len(), 1);
463 assert_eq!(toasts.entries()[0].subject, "Meeting b");
464 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Started);
465 }
466
467 #[test]
468 fn a_snoozed_toast_comes_back_at_the_start_with_a_chime() {
469 let events = [event("a")];
470 let mut toasts = MeetingToasts::default();
471 tick(&mut toasts, &events, at(8, 55, 0), true);
472 let id = toasts.entries()[0].id;
473 toasts.snooze(id);
474 let quiet = tick(&mut toasts, &events, at(8, 58, 0), true);
475 assert!(!quiet.changed && !quiet.chime);
476 let update = tick(&mut toasts, &events, at(9, 0, 0), true);
477 assert!(update.changed && update.chime);
478 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Started);
479 }
480
481 #[test]
482 fn a_snoozed_toast_comes_back_live_before_the_start_with_a_chime() {
483 let events = [live_event("a")];
484 let mut toasts = MeetingToasts::default();
485 tick(&mut toasts, &events, at(8, 55, 0), true);
486 let id = toasts.entries()[0].id;
487 toasts.snooze(id);
488 let update = tick_live(&mut toasts, &events, at(8, 57, 0));
489 assert!(update.changed && update.chime);
490 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Live);
491 }
492
493 #[test]
494 fn a_toast_closed_with_the_corner_x_stays_gone_when_the_meeting_goes_live() {
495 let events = [live_event("a")];
496 let mut toasts = MeetingToasts::default();
497 tick(&mut toasts, &events, at(8, 55, 0), true);
498 let id = toasts.entries()[0].id;
499 toasts.dismiss(id);
500 let update = tick_live(&mut toasts, &events, at(8, 57, 0));
501 assert!(!update.changed && !update.chime);
502 assert!(toasts.is_empty());
503 }
504
505 #[test]
506 fn started_then_live_chimes_once() {
507 let events = [live_event("a")];
508 let mut toasts = MeetingToasts::default();
509 assert!(tick(&mut toasts, &events, at(9, 0, 0), true).chime);
510 let update = tick_live(&mut toasts, &events, at(9, 1, 0));
511 assert!(update.changed && !update.chime);
512 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Live);
513 assert!(!tick(&mut toasts, &events, at(9, 2, 0), true).chime);
514 }
515
516 #[test]
517 fn live_then_started_chimes_once() {
518 let events = [live_event("a")];
519 let mut toasts = MeetingToasts::default();
520 assert!(tick_live(&mut toasts, &events, at(8, 58, 0)).chime);
521 assert!(!tick_live(&mut toasts, &events, at(9, 0, 0)).chime);
522 let update = tick(&mut toasts, &events, at(9, 1, 0), true);
523 assert!(!update.chime);
524 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Started);
525 }
526
527 #[test]
528 fn the_live_phase_covers_the_window_and_wins_over_soon_and_started() {
529 let meeting = event("a");
530 assert_eq!(phase_at(&meeting, at(8, 54, 59), true), None);
531 assert_eq!(
532 phase_at(&meeting, at(8, 55, 0), true),
533 Some(ReminderPhase::Live)
534 );
535 assert_eq!(
536 phase_at(&meeting, at(9, 0, 0), true),
537 Some(ReminderPhase::Live)
538 );
539 assert_eq!(
540 phase_at(&meeting, at(9, 4, 59), true),
541 Some(ReminderPhase::Live)
542 );
543 assert_eq!(phase_at(&meeting, at(9, 5, 0), true), None);
544 let declined = CalendarEvent {
545 response: ResponseType::Declined,
546 ..event("a")
547 };
548 assert_eq!(phase_at(&declined, at(9, 0, 0), true), None);
549 }
550
551 #[test]
552 fn a_hidden_reminder_never_chimes_later() {
553 let events = [live_event("a")];
554 let mut toasts = MeetingToasts::default();
555 tick(&mut toasts, &events, at(8, 56, 0), false);
556 let update = tick_live(&mut toasts, &events, at(8, 58, 0));
557 assert!(!update.chime);
558 assert!(!tick(&mut toasts, &events, at(9, 0, 0), true).chime);
559 }
560
561 #[test]
562 fn live_state_is_polled_every_thirty_seconds_inside_the_window() {
563 let events = [live_event("a"), event("b")];
564 let mut toasts = MeetingToasts::default();
565 assert!(toasts.live_candidates(&events, at(8, 54, 0)).is_empty());
566 assert_eq!(
567 toasts.live_candidates(&events, at(8, 55, 0)),
568 vec!["thread".to_owned()]
569 );
570 assert!(toasts.live_candidates(&events, at(8, 55, 29)).is_empty());
571 assert_eq!(toasts.live_candidates(&events, at(8, 55, 30)).len(), 1);
572 tick(&mut toasts, &events, at(8, 56, 0), true);
573 let id = toasts.entries()[0].id;
574 toasts.dismiss(id);
575 assert!(toasts.live_candidates(&events, at(8, 57, 0)).is_empty());
296 576 }
297 577
298 578 #[test]
299 579 fn a_hidden_reminder_is_spent_and_does_not_appear_later() {
300 580 let events = [event("a")];
301 581 let mut toasts = MeetingToasts::default();
302 assert!(!toasts.update(&events, at(8, 56, 0), false));
303 assert!(!toasts.update(&events, at(8, 57, 0), true));
582 assert!(!tick(&mut toasts, &events, at(8, 56, 0), false).changed);
583 assert!(!tick(&mut toasts, &events, at(8, 57, 0), true).changed);
304 584 assert!(toasts.is_empty());
305 585 }
306 586
@@ -308,12 +588,12 @@ mod tests {
308 588 fn toasts_leave_when_the_window_closes_or_the_event_goes() {
309 589 let events = [event("a")];
310 590 let mut toasts = MeetingToasts::default();
311 toasts.update(&events, at(8, 56, 0), true);
312 assert!(toasts.update(&events, at(9, 5, 0), true));
591 tick(&mut toasts, &events, at(8, 56, 0), true);
592 assert!(tick(&mut toasts, &events, at(9, 5, 0), true).changed);
313 593 assert!(toasts.is_empty());
314 594 let mut removed = MeetingToasts::default();
315 removed.update(&events, at(8, 56, 0), true);
316 assert!(removed.update(&[], at(8, 57, 0), true));
595 tick(&mut removed, &events, at(8, 56, 0), true);
596 assert!(tick(&mut removed, &[], at(8, 57, 0), true).changed);
317 597 assert!(removed.is_empty());
318 598 }
319 599
@@ -321,7 +601,7 @@ mod tests {
321 601 fn the_latest_toast_is_the_one_a_shortcut_joins() {
322 602 let events = [event("a"), event("b")];
323 603 let mut toasts = MeetingToasts::default();
324 toasts.update(&events, at(8, 56, 0), true);
604 tick(&mut toasts, &events, at(8, 56, 0), true);
325 605 assert_eq!(
326 606 toasts.latest().map(|toast| toast.subject.as_str()),
327 607 Some("Meeting b")
@@ -357,13 +637,17 @@ mod tests {
357 637 subtitle(&toast(ReminderPhase::Started), at(9, 1, 0), offset),
358 638 "11:00 - started"
359 639 );
640 assert_eq!(
641 subtitle(&toast(ReminderPhase::Live), at(8, 57, 0), offset),
642 "11:00 - live now"
643 );
360 644 }
361 645
362 646 #[test]
363 647 fn clearing_removes_every_open_toast() {
364 648 let events = [event("a"), event("b")];
365 649 let mut toasts = MeetingToasts::default();
366 toasts.update(&events, at(8, 56, 0), true);
650 tick(&mut toasts, &events, at(8, 56, 0), true);
367 651 assert!(toasts.clear());
368 652 assert!(toasts.is_empty());
369 653 assert!(!toasts.clear());
@@ -373,7 +657,7 @@ mod tests {
373 657 fn checks_run_at_most_once_a_second() {
374 658 let mut toasts = MeetingToasts::default();
375 659 assert!(toasts.is_due_for_check(at(9, 0, 0)));
376 toasts.update(&[], at(9, 0, 0), true);
660 tick(&mut toasts, &[], at(9, 0, 0), true);
377 661 assert!(!toasts.is_due_for_check(at(9, 0, 0)));
378 662 assert!(toasts.is_due_for_check(at(9, 0, 1)));
379 663 }
@@ -9,11 +9,13 @@ use crate::app_state::{AppEvent, AppState};
9pub const LEAD_MINUTES: i64 = 5;
9pub const LEAD_MINUTES: i64 = 5;
10pub const GRACE_MINUTES: i64 = 5;
10pub const GRACE_MINUTES: i64 = 5;
11const CHECK_EVERY_SECONDS: i64 = 1;
11const CHECK_EVERY_SECONDS: i64 = 1;
12const LIVE_POLL_SECONDS: i64 = 30;
12
13
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
14pub enum ReminderPhase {
15pub enum ReminderPhase {
15 Soon,
16 Soon,
16 Started,
17 Started,
18 Live,
17}
19}
18
20
19#[derive(Debug, Clone, PartialEq, Eq)]
21#[derive(Debug, Clone, PartialEq, Eq)]
@@ -30,7 +32,7 @@ fn event_key(event: &CalendarEvent) -> String {
30 format!("{}@{}", event.object_id, event.start.timestamp())
32 format!("{}@{}", event.object_id, event.start.timestamp())
31}
33}
32
34
33pub fn phase_at(event: &CalendarEvent, now: DateTime<Utc>) -> Option<ReminderPhase> {
35pub fn phase_at(event: &CalendarEvent, now: DateTime<Utc>, live: bool) -> Option<ReminderPhase> {
34 let eligible = event.online
36 let eligible = event.online
35 && !event.cancelled
37 && !event.cancelled
36 && !event.all_day
38 && !event.all_day
@@ -39,19 +41,37 @@ pub fn phase_at(event: &CalendarEvent, now: DateTime<Utc>) -> Option<ReminderPha
39 if !eligible {
41 if !eligible {
40 return None;
42 return None;
41 }
43 }
42 if now >= event.start - Duration::minutes(LEAD_MINUTES) && now < event.start {
44 let opens = event.start - Duration::minutes(LEAD_MINUTES);
43 return Some(ReminderPhase::Soon);
44 }
45 let started_until = event
45 let started_until = event
46 .end
46 .end
47 .min(event.start + Duration::minutes(GRACE_MINUTES));
47 .min(event.start + Duration::minutes(GRACE_MINUTES));
48 if live && now >= opens && now < started_until {
49 return Some(ReminderPhase::Live);
50 }
51 if now >= opens && now < event.start {
52 return Some(ReminderPhase::Soon);
53 }
48 (now >= event.start && now < started_until).then_some(ReminderPhase::Started)
54 (now >= event.start && now < started_until).then_some(ReminderPhase::Started)
49}
55}
50
56
57fn is_live(event: &CalendarEvent, live_threads: &HashSet<String>) -> bool {
58 event
59 .thread_id
60 .as_ref()
61 .is_some_and(|thread_id| live_threads.contains(thread_id))
62}
63
64#[derive(Debug, Clone, Copy, PartialEq, Eq)]
65pub struct ReminderUpdate {
66 pub changed: bool,
67 pub chime: bool,
68}
69
51pub fn subtitle(toast: &MeetingToast, now: DateTime<Utc>, offset: FixedOffset) -> String {
70pub fn subtitle(toast: &MeetingToast, now: DateTime<Utc>, offset: FixedOffset) -> String {
52 let clock = toast.start.with_timezone(&offset).format("%H:%M");
71 let clock = toast.start.with_timezone(&offset).format("%H:%M");
53 match toast.phase {
72 match toast.phase {
54 ReminderPhase::Started => format!("{clock} - started"),
73 ReminderPhase::Started => format!("{clock} - started"),
74 ReminderPhase::Live => format!("{clock} - live now"),
55 ReminderPhase::Soon => {
75 ReminderPhase::Soon => {
56 let minutes = ((toast.start - now).num_seconds().max(0) + 59) / 60;
76 let minutes = ((toast.start - now).num_seconds().max(0) + 59) / 60;
57 match minutes {
77 match minutes {
@@ -67,8 +87,12 @@ pub fn subtitle(toast: &MeetingToast, now: DateTime<Utc>, offset: FixedOffset) -
67pub struct MeetingToasts {
87pub struct MeetingToasts {
68 entries: Vec<MeetingToast>,
88 entries: Vec<MeetingToast>,
69 fired: HashSet<(String, ReminderPhase)>,
89 fired: HashSet<(String, ReminderPhase)>,
90 snoozed: HashSet<String>,
91 dismissed: HashSet<String>,
92 chimed: HashSet<String>,
70 next_id: u64,
93 next_id: u64,
71 last_check: Option<DateTime<Utc>>,
94 last_check: Option<DateTime<Utc>>,
95 last_live_poll: Option<DateTime<Utc>>,
72}
96}
73
97
74impl MeetingToasts {
98impl MeetingToasts {
@@ -90,7 +114,16 @@ impl MeetingToasts {
90
114
91 pub fn dismiss(&mut self, id: u64) -> Option<MeetingToast> {
115 pub fn dismiss(&mut self, id: u64) -> Option<MeetingToast> {
92 let index = self.entries.iter().position(|toast| toast.id == id)?;
116 let index = self.entries.iter().position(|toast| toast.id == id)?;
93 Some(self.entries.remove(index))
117 let toast = self.entries.remove(index);
118 self.dismissed.insert(toast.event_key.clone());
119 Some(toast)
120 }
121
122 pub fn snooze(&mut self, id: u64) -> Option<MeetingToast> {
123 let index = self.entries.iter().position(|toast| toast.id == id)?;
124 let toast = self.entries.remove(index);
125 self.snoozed.insert(toast.event_key.clone());
126 Some(toast)
94 }
127 }
95
128
96 pub fn clear(&mut self) -> bool {
129 pub fn clear(&mut self) -> bool {
@@ -104,22 +137,75 @@ impl MeetingToasts {
104 .is_none_or(|last| now - last >= Duration::seconds(CHECK_EVERY_SECONDS))
137 .is_none_or(|last| now - last >= Duration::seconds(CHECK_EVERY_SECONDS))
105 }
138 }
106
139
107 pub fn update(&mut self, events: &[CalendarEvent], now: DateTime<Utc>, show: bool) -> bool {
140 pub fn live_candidates(&mut self, events: &[CalendarEvent], now: DateTime<Utc>) -> Vec<String> {
141 let due = self
142 .last_live_poll
143 .is_none_or(|last| now - last >= Duration::seconds(LIVE_POLL_SECONDS));
144 if !due {
145 return Vec::new();
146 }
147 let candidates: Vec<String> = events
148 .iter()
149 .filter(|event| {
150 phase_at(event, now, false).is_some() && !self.dismissed.contains(&event_key(event))
151 })
152 .filter_map(|event| event.thread_id.clone())
153 .collect();
154 if !candidates.is_empty() {
155 self.last_live_poll = Some(now);
156 }
157 candidates
158 }
159
160 pub fn update(
161 &mut self,
162 events: &[CalendarEvent],
163 live_threads: &HashSet<String>,
164 now: DateTime<Utc>,
165 show: bool,
166 ) -> ReminderUpdate {
108 self.last_check = Some(now);
167 self.last_check = Some(now);
109 let before = self.entries.clone();
168 let before = self.entries.clone();
110 self.entries.retain(|toast| {
169 self.entries.retain(|toast| {
111 events
170 events.iter().any(|event| {
112 .iter()
171 event_key(event) == toast.event_key
113 .any(|event| event_key(event) == toast.event_key && phase_at(event, now).is_some())
172 && phase_at(event, now, is_live(event, live_threads)).is_some()
173 })
114 });
174 });
115 let keys: HashSet<String> = events.iter().map(event_key).collect();
175 let keys: HashSet<String> = events.iter().map(event_key).collect();
116 self.fired.retain(|(key, _)| keys.contains(key));
176 self.fired.retain(|(key, _)| keys.contains(key));
177 self.snoozed.retain(|key| keys.contains(key));
178 self.dismissed.retain(|key| keys.contains(key));
179 self.chimed.retain(|key| keys.contains(key));
180 let mut chime = false;
117 for event in events {
181 for event in events {
118 let Some(phase) = phase_at(event, now) else {
182 let Some(phase) = phase_at(event, now, is_live(event, live_threads)) else {
119 continue;
183 continue;
120 };
184 };
121 let key = event_key(event);
185 let key = event_key(event);
122 if !self.fired.insert((key.clone(), phase)) || !show {
186 if self.dismissed.contains(&key) {
187 continue;
188 }
189 let chime_due = phase != ReminderPhase::Soon && !self.chimed.contains(&key);
190 if let Some(existing) = self.entries.iter_mut().find(|toast| toast.event_key == key) {
191 existing.phase = phase;
192 if chime_due {
193 self.chimed.insert(key);
194 chime |= show;
195 }
196 continue;
197 }
198 if self.snoozed.contains(&key) {
199 if phase == ReminderPhase::Soon {
200 continue;
201 }
202 self.snoozed.remove(&key);
203 } else if self.fired.contains(&(key.clone(), phase)) {
204 continue;
205 }
206 self.fired.insert((key.clone(), phase));
207 if !show {
208 self.chimed.insert(key);
123 continue;
209 continue;
124 }
210 }
125 let Some(join_url) = event.join_url.clone() else {
211 let Some(join_url) = event.join_url.clone() else {
@@ -130,9 +216,9 @@ impl MeetingToasts {
130 } else {
216 } else {
131 event.subject.clone()
217 event.subject.clone()
132 };
218 };
133 if let Some(existing) = self.entries.iter_mut().find(|toast| toast.event_key == key) {
219 if chime_due {
134 existing.phase = phase;
220 self.chimed.insert(key.clone());
135 continue;
221 chime = true;
136 }
222 }
137 self.next_id += 1;
223 self.next_id += 1;
138 self.entries.push(MeetingToast {
224 self.entries.push(MeetingToast {
@@ -144,7 +230,10 @@ impl MeetingToasts {
144 join_url,
230 join_url,
145 });
231 });
146 }
232 }
147 self.entries != before
233 ReminderUpdate {
234 changed: self.entries != before,
235 chime,
236 }
148 }
237 }
149}
238}
150
239
@@ -153,11 +242,28 @@ impl AppState {
153 let now = Utc::now();
242 let now = Utc::now();
154 let in_call = self.call.is_some();
243 let in_call = self.call.is_some();
155 let show = show && !in_call && !self.mode.read_only;
244 let show = show && !in_call && !self.mode.read_only;
156 let changed = self.meeting_toasts.update(&self.calendar_events, now, show);
245 for thread_id in self
157 if (in_call && self.meeting_toasts.clear()) || changed {
246 .meeting_toasts
247 .live_candidates(&self.calendar_events, now)
248 {
249 self.fetch_live_meeting(&thread_id, cx);
250 }
251 let live_threads: HashSet<String> = self
252 .calendar_events
253 .iter()
254 .filter_map(|event| event.thread_id.clone())
255 .filter(|thread_id| self.running_meeting(thread_id).is_some())
256 .collect();
257 let update = self
258 .meeting_toasts
259 .update(&self.calendar_events, &live_threads, now, show);
260 if (in_call && self.meeting_toasts.clear()) || update.changed {
158 cx.emit(AppEvent::MeetingReminder);
261 cx.emit(AppEvent::MeetingReminder);
159 cx.notify();
262 cx.notify();
160 }
263 }
264 if update.chime {
265 cx.emit(AppEvent::MeetingChime);
266 }
161 }
267 }
162
268
163 pub fn join_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
269 pub fn join_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
@@ -177,6 +283,13 @@ impl AppState {
177 }
283 }
178 }
284 }
179
285
286 pub fn snooze_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
287 if self.meeting_toasts.snooze(id).is_some() {
288 cx.emit(AppEvent::MeetingReminder);
289 cx.notify();
290 }
291 }
292
180 pub fn dismiss_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
293 pub fn dismiss_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
181 if self.meeting_toasts.dismiss(id).is_some() {
294 if self.meeting_toasts.dismiss(id).is_some() {
182 cx.emit(AppEvent::MeetingReminder);
295 cx.emit(AppEvent::MeetingReminder);
@@ -214,21 +327,52 @@ mod tests {
214 }
327 }
215 }
328 }
216
329
330 fn tick(
331 toasts: &mut MeetingToasts,
332 events: &[CalendarEvent],
333 now: DateTime<Utc>,
334 show: bool,
335 ) -> ReminderUpdate {
336 toasts.update(events, &HashSet::new(), now, show)
337 }
338
339 fn tick_live(
340 toasts: &mut MeetingToasts,
341 events: &[CalendarEvent],
342 now: DateTime<Utc>,
343 ) -> ReminderUpdate {
344 let live_threads = HashSet::from(["thread".to_owned()]);
345 toasts.update(events, &live_threads, now, true)
346 }
347
348 fn live_event(id: &str) -> CalendarEvent {
349 CalendarEvent {
350 thread_id: Some("thread".into()),
351 ..event(id)
352 }
353 }
354
217 #[test]
355 #[test]
218 fn the_phase_follows_the_clock_around_the_start() {
356 fn the_phase_follows_the_clock_around_the_start() {
219 let meeting = event("a");
357 let meeting = event("a");
220 assert_eq!(phase_at(&meeting, at(8, 54, 59)), None);
358 assert_eq!(phase_at(&meeting, at(8, 54, 59), false), None);
221 assert_eq!(phase_at(&meeting, at(8, 55, 0)), Some(ReminderPhase::Soon));
359 assert_eq!(
222 assert_eq!(phase_at(&meeting, at(8, 59, 59)), Some(ReminderPhase::Soon));
360 phase_at(&meeting, at(8, 55, 0), false),
361 Some(ReminderPhase::Soon)
362 );
363 assert_eq!(
364 phase_at(&meeting, at(8, 59, 59), false),
365 Some(ReminderPhase::Soon)
366 );
223 assert_eq!(
367 assert_eq!(
224 phase_at(&meeting, at(9, 0, 0)),
368 phase_at(&meeting, at(9, 0, 0), false),
225 Some(ReminderPhase::Started)
369 Some(ReminderPhase::Started)
226 );
370 );
227 assert_eq!(
371 assert_eq!(
228 phase_at(&meeting, at(9, 4, 59)),
372 phase_at(&meeting, at(9, 4, 59), false),
229 Some(ReminderPhase::Started)
373 Some(ReminderPhase::Started)
230 );
374 );
231 assert_eq!(phase_at(&meeting, at(9, 5, 0)), None);
375 assert_eq!(phase_at(&meeting, at(9, 5, 0), false), None);
232 }
376 }
233
377
234 #[test]
378 #[test]
@@ -237,8 +381,11 @@ mod tests {
237 end: at(9, 3, 0),
381 end: at(9, 3, 0),
238 ..event("a")
382 ..event("a")
239 };
383 };
240 assert_eq!(phase_at(&short, at(9, 2, 59)), Some(ReminderPhase::Started));
384 assert_eq!(
241 assert_eq!(phase_at(&short, at(9, 3, 0)), None);
385 phase_at(&short, at(9, 2, 59), false),
386 Some(ReminderPhase::Started)
387 );
388 assert_eq!(phase_at(&short, at(9, 3, 0), false), None);
242 }
389 }
243
390
244 #[test]
391 #[test]
@@ -260,7 +407,7 @@ mod tests {
260 ..event("a")
407 ..event("a")
261 };
408 };
262 for quiet in [declined, cancelled, all_day, offline] {
409 for quiet in [declined, cancelled, all_day, offline] {
263 assert_eq!(phase_at(&quiet, at(8, 58, 0)), None);
410 assert_eq!(phase_at(&quiet, at(8, 58, 0), false), None);
264 }
411 }
265 }
412 }
266
413
@@ -268,39 +415,172 @@ mod tests {
268 fn each_phase_fires_once_per_meeting() {
415 fn each_phase_fires_once_per_meeting() {
269 let events = [event("a")];
416 let events = [event("a")];
270 let mut toasts = MeetingToasts::default();
417 let mut toasts = MeetingToasts::default();
271 assert!(!toasts.update(&events, at(8, 54, 0), true));
418 assert!(!tick(&mut toasts, &events, at(8, 54, 0), true).changed);
272 assert!(toasts.update(&events, at(8, 55, 0), true));
419 assert!(tick(&mut toasts, &events, at(8, 55, 0), true).changed);
273 assert_eq!(toasts.entries().len(), 1);
420 assert_eq!(toasts.entries().len(), 1);
274 let id = toasts.entries()[0].id;
421 let id = toasts.entries()[0].id;
275 toasts.dismiss(id);
422 toasts.dismiss(id);
276 assert!(!toasts.update(&events, at(8, 56, 0), true));
423 assert!(!tick(&mut toasts, &events, at(8, 56, 0), true).changed);
277 assert!(toasts.is_empty());
424 assert!(toasts.is_empty());
278 }
425 }
279
426
280 #[test]
427 #[test]
281 fn the_start_brings_a_dismissed_toast_back_and_updates_an_open_one() {
428 fn the_start_moves_an_open_toast_to_started_and_chimes() {
282 let events = [event("a")];
429 let events = [event("a")];
283 let mut toasts = MeetingToasts::default();
430 let mut toasts = MeetingToasts::default();
284 toasts.update(&events, at(8, 55, 0), true);
431 assert!(!tick(&mut toasts, &events, at(8, 55, 0), true).chime);
285 let id = toasts.entries()[0].id;
432 let id = toasts.entries()[0].id;
286 assert!(toasts.update(&events, at(9, 0, 0), true));
433 let update = tick(&mut toasts, &events, at(9, 0, 0), true);
434 assert!(update.changed && update.chime);
287 assert_eq!(toasts.entries().len(), 1);
435 assert_eq!(toasts.entries().len(), 1);
288 assert_eq!(toasts.entries()[0].id, id);
436 assert_eq!(toasts.entries()[0].id, id);
289 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Started);
437 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Started);
290 let mut dismissed = MeetingToasts::default();
438 assert!(!tick(&mut toasts, &events, at(9, 1, 0), true).chime);
291 dismissed.update(&events, at(8, 55, 0), true);
439 }
292 let soon_id = dismissed.entries()[0].id;
440
293 dismissed.dismiss(soon_id);
441 #[test]
294 assert!(dismissed.update(&events, at(9, 0, 0), true));
442 fn a_toast_closed_with_the_corner_x_stays_gone_and_silent() {
295 assert_eq!(dismissed.entries()[0].phase, ReminderPhase::Started);
443 let events = [event("a")];
444 let mut toasts = MeetingToasts::default();
445 tick(&mut toasts, &events, at(8, 55, 0), true);
446 let id = toasts.entries()[0].id;
447 toasts.dismiss(id);
448 let update = tick(&mut toasts, &events, at(9, 0, 0), true);
449 assert!(!update.changed && !update.chime);
450 assert!(toasts.is_empty());
451 }
452
453 #[test]
454 fn the_corner_x_only_closes_its_own_meeting() {
455 let events = [event("a"), event("b")];
456 let mut toasts = MeetingToasts::default();
457 tick(&mut toasts, &events, at(8, 55, 0), true);
458 let first = toasts.entries()[0].id;
459 toasts.dismiss(first);
460 let update = tick(&mut toasts, &events, at(9, 0, 0), true);
461 assert!(update.chime);
462 assert_eq!(toasts.entries().len(), 1);
463 assert_eq!(toasts.entries()[0].subject, "Meeting b");
464 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Started);
465 }
466
467 #[test]
468 fn a_snoozed_toast_comes_back_at_the_start_with_a_chime() {
469 let events = [event("a")];
470 let mut toasts = MeetingToasts::default();
471 tick(&mut toasts, &events, at(8, 55, 0), true);
472 let id = toasts.entries()[0].id;
473 toasts.snooze(id);
474 let quiet = tick(&mut toasts, &events, at(8, 58, 0), true);
475 assert!(!quiet.changed && !quiet.chime);
476 let update = tick(&mut toasts, &events, at(9, 0, 0), true);
477 assert!(update.changed && update.chime);
478 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Started);
479 }
480
481 #[test]
482 fn a_snoozed_toast_comes_back_live_before_the_start_with_a_chime() {
483 let events = [live_event("a")];
484 let mut toasts = MeetingToasts::default();
485 tick(&mut toasts, &events, at(8, 55, 0), true);
486 let id = toasts.entries()[0].id;
487 toasts.snooze(id);
488 let update = tick_live(&mut toasts, &events, at(8, 57, 0));
489 assert!(update.changed && update.chime);
490 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Live);
491 }
492
493 #[test]
494 fn a_toast_closed_with_the_corner_x_stays_gone_when_the_meeting_goes_live() {
495 let events = [live_event("a")];
496 let mut toasts = MeetingToasts::default();
497 tick(&mut toasts, &events, at(8, 55, 0), true);
498 let id = toasts.entries()[0].id;
499 toasts.dismiss(id);
500 let update = tick_live(&mut toasts, &events, at(8, 57, 0));
501 assert!(!update.changed && !update.chime);
502 assert!(toasts.is_empty());
503 }
504
505 #[test]
506 fn started_then_live_chimes_once() {
507 let events = [live_event("a")];
508 let mut toasts = MeetingToasts::default();
509 assert!(tick(&mut toasts, &events, at(9, 0, 0), true).chime);
510 let update = tick_live(&mut toasts, &events, at(9, 1, 0));
511 assert!(update.changed && !update.chime);
512 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Live);
513 assert!(!tick(&mut toasts, &events, at(9, 2, 0), true).chime);
514 }
515
516 #[test]
517 fn live_then_started_chimes_once() {
518 let events = [live_event("a")];
519 let mut toasts = MeetingToasts::default();
520 assert!(tick_live(&mut toasts, &events, at(8, 58, 0)).chime);
521 assert!(!tick_live(&mut toasts, &events, at(9, 0, 0)).chime);
522 let update = tick(&mut toasts, &events, at(9, 1, 0), true);
523 assert!(!update.chime);
524 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Started);
525 }
526
527 #[test]
528 fn the_live_phase_covers_the_window_and_wins_over_soon_and_started() {
529 let meeting = event("a");
530 assert_eq!(phase_at(&meeting, at(8, 54, 59), true), None);
531 assert_eq!(
532 phase_at(&meeting, at(8, 55, 0), true),
533 Some(ReminderPhase::Live)
534 );
535 assert_eq!(
536 phase_at(&meeting, at(9, 0, 0), true),
537 Some(ReminderPhase::Live)
538 );
539 assert_eq!(
540 phase_at(&meeting, at(9, 4, 59), true),
541 Some(ReminderPhase::Live)
542 );
543 assert_eq!(phase_at(&meeting, at(9, 5, 0), true), None);
544 let declined = CalendarEvent {
545 response: ResponseType::Declined,
546 ..event("a")
547 };
548 assert_eq!(phase_at(&declined, at(9, 0, 0), true), None);
549 }
550
551 #[test]
552 fn a_hidden_reminder_never_chimes_later() {
553 let events = [live_event("a")];
554 let mut toasts = MeetingToasts::default();
555 tick(&mut toasts, &events, at(8, 56, 0), false);
556 let update = tick_live(&mut toasts, &events, at(8, 58, 0));
557 assert!(!update.chime);
558 assert!(!tick(&mut toasts, &events, at(9, 0, 0), true).chime);
559 }
560
561 #[test]
562 fn live_state_is_polled_every_thirty_seconds_inside_the_window() {
563 let events = [live_event("a"), event("b")];
564 let mut toasts = MeetingToasts::default();
565 assert!(toasts.live_candidates(&events, at(8, 54, 0)).is_empty());
566 assert_eq!(
567 toasts.live_candidates(&events, at(8, 55, 0)),
568 vec!["thread".to_owned()]
569 );
570 assert!(toasts.live_candidates(&events, at(8, 55, 29)).is_empty());
571 assert_eq!(toasts.live_candidates(&events, at(8, 55, 30)).len(), 1);
572 tick(&mut toasts, &events, at(8, 56, 0), true);
573 let id = toasts.entries()[0].id;
574 toasts.dismiss(id);
575 assert!(toasts.live_candidates(&events, at(8, 57, 0)).is_empty());
296 }
576 }
297
577
298 #[test]
578 #[test]
299 fn a_hidden_reminder_is_spent_and_does_not_appear_later() {
579 fn a_hidden_reminder_is_spent_and_does_not_appear_later() {
300 let events = [event("a")];
580 let events = [event("a")];
301 let mut toasts = MeetingToasts::default();
581 let mut toasts = MeetingToasts::default();
302 assert!(!toasts.update(&events, at(8, 56, 0), false));
582 assert!(!tick(&mut toasts, &events, at(8, 56, 0), false).changed);
303 assert!(!toasts.update(&events, at(8, 57, 0), true));
583 assert!(!tick(&mut toasts, &events, at(8, 57, 0), true).changed);
304 assert!(toasts.is_empty());
584 assert!(toasts.is_empty());
305 }
585 }
306
586
@@ -308,12 +588,12 @@ mod tests {
308 fn toasts_leave_when_the_window_closes_or_the_event_goes() {
588 fn toasts_leave_when_the_window_closes_or_the_event_goes() {
309 let events = [event("a")];
589 let events = [event("a")];
310 let mut toasts = MeetingToasts::default();
590 let mut toasts = MeetingToasts::default();
311 toasts.update(&events, at(8, 56, 0), true);
591 tick(&mut toasts, &events, at(8, 56, 0), true);
312 assert!(toasts.update(&events, at(9, 5, 0), true));
592 assert!(tick(&mut toasts, &events, at(9, 5, 0), true).changed);
313 assert!(toasts.is_empty());
593 assert!(toasts.is_empty());
314 let mut removed = MeetingToasts::default();
594 let mut removed = MeetingToasts::default();
315 removed.update(&events, at(8, 56, 0), true);
595 tick(&mut removed, &events, at(8, 56, 0), true);
316 assert!(removed.update(&[], at(8, 57, 0), true));
596 assert!(tick(&mut removed, &[], at(8, 57, 0), true).changed);
317 assert!(removed.is_empty());
597 assert!(removed.is_empty());
318 }
598 }
319
599
@@ -321,7 +601,7 @@ mod tests {
321 fn the_latest_toast_is_the_one_a_shortcut_joins() {
601 fn the_latest_toast_is_the_one_a_shortcut_joins() {
322 let events = [event("a"), event("b")];
602 let events = [event("a"), event("b")];
323 let mut toasts = MeetingToasts::default();
603 let mut toasts = MeetingToasts::default();
324 toasts.update(&events, at(8, 56, 0), true);
604 tick(&mut toasts, &events, at(8, 56, 0), true);
325 assert_eq!(
605 assert_eq!(
326 toasts.latest().map(|toast| toast.subject.as_str()),
606 toasts.latest().map(|toast| toast.subject.as_str()),
327 Some("Meeting b")
607 Some("Meeting b")
@@ -357,13 +637,17 @@ mod tests {
357 subtitle(&toast(ReminderPhase::Started), at(9, 1, 0), offset),
637 subtitle(&toast(ReminderPhase::Started), at(9, 1, 0), offset),
358 "11:00 - started"
638 "11:00 - started"
359 );
639 );
640 assert_eq!(
641 subtitle(&toast(ReminderPhase::Live), at(8, 57, 0), offset),
642 "11:00 - live now"
643 );
360 }
644 }
361
645
362 #[test]
646 #[test]
363 fn clearing_removes_every_open_toast() {
647 fn clearing_removes_every_open_toast() {
364 let events = [event("a"), event("b")];
648 let events = [event("a"), event("b")];
365 let mut toasts = MeetingToasts::default();
649 let mut toasts = MeetingToasts::default();
366 toasts.update(&events, at(8, 56, 0), true);
650 tick(&mut toasts, &events, at(8, 56, 0), true);
367 assert!(toasts.clear());
651 assert!(toasts.clear());
368 assert!(toasts.is_empty());
652 assert!(toasts.is_empty());
369 assert!(!toasts.clear());
653 assert!(!toasts.clear());
@@ -373,7 +657,7 @@ mod tests {
373 fn checks_run_at_most_once_a_second() {
657 fn checks_run_at_most_once_a_second() {
374 let mut toasts = MeetingToasts::default();
658 let mut toasts = MeetingToasts::default();
375 assert!(toasts.is_due_for_check(at(9, 0, 0)));
659 assert!(toasts.is_due_for_check(at(9, 0, 0)));
376 toasts.update(&[], at(9, 0, 0), true);
660 tick(&mut toasts, &[], at(9, 0, 0), true);
377 assert!(!toasts.is_due_for_check(at(9, 0, 0)));
661 assert!(!toasts.is_due_for_check(at(9, 0, 0)));
378 assert!(toasts.is_due_for_check(at(9, 0, 1)));
662 assert!(toasts.is_due_for_check(at(9, 0, 1)));
379 }
663 }
crates/app/src/notify/center.rs +7 −0
@@ -247,6 +247,7 @@ impl NotificationCenter {
247 247 AppEvent::Sidebar => self.refresh_badge(cx),
248 248 AppEvent::Ring => self.on_rings_changed(cx),
249 249 AppEvent::MeetingReminder => self.on_meeting_reminder(cx),
250 AppEvent::MeetingChime => self.on_meeting_chime(cx),
250 251 AppEvent::Call => self.sync_ringback(cx),
251 252 _ => {}
252 253 }
@@ -565,6 +566,12 @@ impl NotificationCenter {
565 566 cx.notify();
566 567 }
567 568
569 fn on_meeting_chime(&mut self, cx: &mut Context<Self>) {
570 if self.settings.sound && !self.reminders_quiet(cx) && !self.demo_mode {
571 platform::play_meeting_chime();
572 }
573 }
574
568 575 pub fn join_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
569 576 self.raise_main_window(cx);
570 577 self.app
@@ -247,6 +247,7 @@ impl NotificationCenter {
247 AppEvent::Sidebar => self.refresh_badge(cx),
247 AppEvent::Sidebar => self.refresh_badge(cx),
248 AppEvent::Ring => self.on_rings_changed(cx),
248 AppEvent::Ring => self.on_rings_changed(cx),
249 AppEvent::MeetingReminder => self.on_meeting_reminder(cx),
249 AppEvent::MeetingReminder => self.on_meeting_reminder(cx),
250 AppEvent::MeetingChime => self.on_meeting_chime(cx),
250 AppEvent::Call => self.sync_ringback(cx),
251 AppEvent::Call => self.sync_ringback(cx),
251 _ => {}
252 _ => {}
252 }
253 }
@@ -565,6 +566,12 @@ impl NotificationCenter {
565 cx.notify();
566 cx.notify();
566 }
567 }
567
568
569 fn on_meeting_chime(&mut self, cx: &mut Context<Self>) {
570 if self.settings.sound && !self.reminders_quiet(cx) && !self.demo_mode {
571 platform::play_meeting_chime();
572 }
573 }
574
568 pub fn join_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
575 pub fn join_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
569 self.raise_main_window(cx);
576 self.raise_main_window(cx);
570 self.app
577 self.app
crates/app/src/notify/meeting_view.rs +51 −8
@@ -1,17 +1,23 @@
1 1 use chrono::{Local, Offset, Utc};
2 2 use gpui_kit::assets::IconName;
3 3 use gpui_kit::component::{h_flex, v_flex};
4 use gpui_kit::prelude::FluentBuilder as _;
4 5 use gpui_kit::*;
5 6
6 7 use super::center::NotificationCenter;
7 8 use super::layout::{AVATAR_GAP, TOAST_PADDING};
8 9 use super::ring_view::{RING_AVATAR, RING_BORDER, TOAST_RADIUS, answer_button};
9 10 use crate::app_state::AppState;
11 use crate::call::ReminderPhase;
10 12 use crate::call::meeting_subtitle;
11 13 use crate::theme;
12 14 use crate::views::widgets::icon;
13 15
14 16 const MEETING_ICON: f32 = 22.;
17 const LIVE_DOT: f32 = 7.;
18 const CLOSE_BUTTON: f32 = 24.;
19 const CLOSE_INSET: f32 = 8.;
20 const CLOSE_CLEARANCE: f32 = 20.;
15 21
16 22 pub struct MeetingToastView {
17 23 center: Entity<NotificationCenter>,
@@ -47,12 +53,13 @@ impl Render for MeetingToastView {
47 53 window.set_window_title(&toast.subject);
48 54 let subtitle = meeting_subtitle(&toast, Utc::now(), Local::now().offset().fix());
49 55 let toast_id = self.toast_id;
50 let dismiss_app = self.app.clone();
51 56 let join_center = self.center.clone();
52 let dismiss = answer_button(
53 "meeting-dismiss",
54 "Dismiss",
55 IconName::Close,
57 let snooze_app = self.app.clone();
58 let dismiss_app = self.app.clone();
59 let snooze = answer_button(
60 "meeting-snooze",
61 "Snooze",
62 IconName::AlarmClock,
56 63 theme::surface_raised(),
57 64 )
58 65 .border_1()
@@ -60,14 +67,37 @@ impl Render for MeetingToastView {
60 67 .text_color(theme::text())
61 68 .on_click(move |_, _, cx| {
62 69 cx.stop_propagation();
63 dismiss_app.update(cx, |state, cx| state.dismiss_meeting_toast(toast_id, cx));
70 snooze_app.update(cx, |state, cx| state.snooze_meeting_toast(toast_id, cx));
64 71 });
72 let dismiss = div()
73 .id("meeting-dismiss")
74 .absolute()
75 .top(px(CLOSE_INSET))
76 .right(px(CLOSE_INSET))
77 .size(px(CLOSE_BUTTON))
78 .flex()
79 .items_center()
80 .justify_center()
81 .rounded(px(6.))
82 .cursor_pointer()
83 .hover(|button| button.bg(theme::row_hover()))
84 .child(icon(IconName::Close, 14., theme::text_muted()))
85 .on_click(move |_, _, cx| {
86 cx.stop_propagation();
87 dismiss_app.update(cx, |state, cx| state.dismiss_meeting_toast(toast_id, cx));
88 });
65 89 let join = answer_button("meeting-join", "Join", IconName::Video, theme::accent())
66 90 .text_color(theme::on_accent())
67 91 .on_click(move |_, _, cx| {
68 92 cx.stop_propagation();
69 93 join_center.update(cx, |center, cx| center.join_meeting_toast(toast_id, cx));
70 94 });
95 let live = toast.phase == ReminderPhase::Live;
96 let buttons = if toast.phase == ReminderPhase::Soon {
97 h_flex().mt(px(8.)).gap(px(6.)).child(snooze).child(join)
98 } else {
99 h_flex().mt(px(8.)).gap(px(6.)).child(join)
100 };
71 101 div()
72 102 .id(("meeting-toast", toast_id))
73 103 .size_full()
@@ -97,6 +127,7 @@ impl Render for MeetingToastView {
97 127 v_flex()
98 128 .flex_1()
99 129 .min_w_0()
130 .pr(px(CLOSE_CLEARANCE))
100 131 .gap(px(2.))
101 132 .child(
102 133 div()
@@ -107,15 +138,27 @@ impl Render for MeetingToastView {
107 138 .child(toast.subject.clone()),
108 139 )
109 140 .child(
110 div()
141 h_flex()
142 .gap(px(6.))
143 .items_center()
111 144 .text_size(px(12.5))
112 145 .text_color(theme::text_muted())
146 .when(live, |row| {
147 row.child(
148 div()
149 .size(px(LIVE_DOT))
150 .flex_none()
151 .rounded_full()
152 .bg(theme::green()),
153 )
154 })
113 155 .child(subtitle),
114 156 )
115 .child(h_flex().mt(px(8.)).gap(px(6.)).child(dismiss).child(join)),
157 .child(buttons),
116 158 ),
117 159 ),
118 160 )
161 .child(dismiss)
119 162 .into_any_element()
120 163 }
121 164 }
@@ -1,17 +1,23 @@
1use chrono::{Local, Offset, Utc};
1use chrono::{Local, Offset, Utc};
2use gpui_kit::assets::IconName;
2use gpui_kit::assets::IconName;
3use gpui_kit::component::{h_flex, v_flex};
3use gpui_kit::component::{h_flex, v_flex};
4use gpui_kit::prelude::FluentBuilder as _;
4use gpui_kit::*;
5use gpui_kit::*;
5
6
6use super::center::NotificationCenter;
7use super::center::NotificationCenter;
7use super::layout::{AVATAR_GAP, TOAST_PADDING};
8use super::layout::{AVATAR_GAP, TOAST_PADDING};
8use super::ring_view::{RING_AVATAR, RING_BORDER, TOAST_RADIUS, answer_button};
9use super::ring_view::{RING_AVATAR, RING_BORDER, TOAST_RADIUS, answer_button};
9use crate::app_state::AppState;
10use crate::app_state::AppState;
11use crate::call::ReminderPhase;
10use crate::call::meeting_subtitle;
12use crate::call::meeting_subtitle;
11use crate::theme;
13use crate::theme;
12use crate::views::widgets::icon;
14use crate::views::widgets::icon;
13
15
14const MEETING_ICON: f32 = 22.;
16const MEETING_ICON: f32 = 22.;
17const LIVE_DOT: f32 = 7.;
18const CLOSE_BUTTON: f32 = 24.;
19const CLOSE_INSET: f32 = 8.;
20const CLOSE_CLEARANCE: f32 = 20.;
15
21
16pub struct MeetingToastView {
22pub struct MeetingToastView {
17 center: Entity<NotificationCenter>,
23 center: Entity<NotificationCenter>,
@@ -47,12 +53,13 @@ impl Render for MeetingToastView {
47 window.set_window_title(&toast.subject);
53 window.set_window_title(&toast.subject);
48 let subtitle = meeting_subtitle(&toast, Utc::now(), Local::now().offset().fix());
54 let subtitle = meeting_subtitle(&toast, Utc::now(), Local::now().offset().fix());
49 let toast_id = self.toast_id;
55 let toast_id = self.toast_id;
50 let dismiss_app = self.app.clone();
51 let join_center = self.center.clone();
56 let join_center = self.center.clone();
52 let dismiss = answer_button(
57 let snooze_app = self.app.clone();
53 "meeting-dismiss",
58 let dismiss_app = self.app.clone();
54 "Dismiss",
59 let snooze = answer_button(
55 IconName::Close,
60 "meeting-snooze",
61 "Snooze",
62 IconName::AlarmClock,
56 theme::surface_raised(),
63 theme::surface_raised(),
57 )
64 )
58 .border_1()
65 .border_1()
@@ -60,14 +67,37 @@ impl Render for MeetingToastView {
60 .text_color(theme::text())
67 .text_color(theme::text())
61 .on_click(move |_, _, cx| {
68 .on_click(move |_, _, cx| {
62 cx.stop_propagation();
69 cx.stop_propagation();
63 dismiss_app.update(cx, |state, cx| state.dismiss_meeting_toast(toast_id, cx));
70 snooze_app.update(cx, |state, cx| state.snooze_meeting_toast(toast_id, cx));
64 });
71 });
72 let dismiss = div()
73 .id("meeting-dismiss")
74 .absolute()
75 .top(px(CLOSE_INSET))
76 .right(px(CLOSE_INSET))
77 .size(px(CLOSE_BUTTON))
78 .flex()
79 .items_center()
80 .justify_center()
81 .rounded(px(6.))
82 .cursor_pointer()
83 .hover(|button| button.bg(theme::row_hover()))
84 .child(icon(IconName::Close, 14., theme::text_muted()))
85 .on_click(move |_, _, cx| {
86 cx.stop_propagation();
87 dismiss_app.update(cx, |state, cx| state.dismiss_meeting_toast(toast_id, cx));
88 });
65 let join = answer_button("meeting-join", "Join", IconName::Video, theme::accent())
89 let join = answer_button("meeting-join", "Join", IconName::Video, theme::accent())
66 .text_color(theme::on_accent())
90 .text_color(theme::on_accent())
67 .on_click(move |_, _, cx| {
91 .on_click(move |_, _, cx| {
68 cx.stop_propagation();
92 cx.stop_propagation();
69 join_center.update(cx, |center, cx| center.join_meeting_toast(toast_id, cx));
93 join_center.update(cx, |center, cx| center.join_meeting_toast(toast_id, cx));
70 });
94 });
95 let live = toast.phase == ReminderPhase::Live;
96 let buttons = if toast.phase == ReminderPhase::Soon {
97 h_flex().mt(px(8.)).gap(px(6.)).child(snooze).child(join)
98 } else {
99 h_flex().mt(px(8.)).gap(px(6.)).child(join)
100 };
71 div()
101 div()
72 .id(("meeting-toast", toast_id))
102 .id(("meeting-toast", toast_id))
73 .size_full()
103 .size_full()
@@ -97,6 +127,7 @@ impl Render for MeetingToastView {
97 v_flex()
127 v_flex()
98 .flex_1()
128 .flex_1()
99 .min_w_0()
129 .min_w_0()
130 .pr(px(CLOSE_CLEARANCE))
100 .gap(px(2.))
131 .gap(px(2.))
101 .child(
132 .child(
102 div()
133 div()
@@ -107,15 +138,27 @@ impl Render for MeetingToastView {
107 .child(toast.subject.clone()),
138 .child(toast.subject.clone()),
108 )
139 )
109 .child(
140 .child(
110 div()
141 h_flex()
142 .gap(px(6.))
143 .items_center()
111 .text_size(px(12.5))
144 .text_size(px(12.5))
112 .text_color(theme::text_muted())
145 .text_color(theme::text_muted())
146 .when(live, |row| {
147 row.child(
148 div()
149 .size(px(LIVE_DOT))
150 .flex_none()
151 .rounded_full()
152 .bg(theme::green()),
153 )
154 })
113 .child(subtitle),
155 .child(subtitle),
114 )
156 )
115 .child(h_flex().mt(px(8.)).gap(px(6.)).child(dismiss).child(join)),
157 .child(buttons),
116 ),
158 ),
117 ),
159 ),
118 )
160 )
161 .child(dismiss)
119 .into_any_element()
162 .into_any_element()
120 }
163 }
121}
164}
crates/app/src/views/conversation.rs +1 −0
@@ -645,6 +645,7 @@ impl ConversationView {
645 645 | AppEvent::Ring
646 646 | AppEvent::MissedCall(_)
647 647 | AppEvent::MeetingReminder
648 | AppEvent::MeetingChime
648 649 | AppEvent::Call => {}
649 650 AppEvent::LiveMeeting => cx.notify(),
650 651 AppEvent::Saved => cx.notify(),
@@ -645,6 +645,7 @@ impl ConversationView {
645 | AppEvent::Ring
645 | AppEvent::Ring
646 | AppEvent::MissedCall(_)
646 | AppEvent::MissedCall(_)
647 | AppEvent::MeetingReminder
647 | AppEvent::MeetingReminder
648 | AppEvent::MeetingChime
648 | AppEvent::Call => {}
649 | AppEvent::Call => {}
649 AppEvent::LiveMeeting => cx.notify(),
650 AppEvent::LiveMeeting => cx.notify(),
650 AppEvent::Saved => cx.notify(),
651 AppEvent::Saved => cx.notify(),