BlueGit

ict rusty-teams

fix(meetings): a closed reminder still pops up once the meeting goes live

- Closing the 5-minute or start reminder keeps the meeting quiet only until someone joins; then the live toast comes, like Teams
- The live toast no longer depends on the Outlook reminder state
- Closing the live toast or joining from a reminder mutes the meeting for good

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-11 · 2 weeks ago

Hash
47241abeb536b3ce0bf3036137ee9b0bb2b669f6
Parent
a90222bb
1 file changed +57 −23
crates/app-state/src/call/reminder.rs +57 −23
@@ -1,4 +1,4 @@
1 use std::collections::HashSet;
1 use std::collections::{HashMap, HashSet};
2 2
3 3 use chatsvc::{CalendarEvent, ResponseType};
4 4 use chrono::{DateTime, Duration, FixedOffset, Utc};
@@ -93,7 +93,7 @@ pub struct MeetingToasts {
93 93 entries: Vec<MeetingToast>,
94 94 fired: HashSet<(String, ReminderPhase)>,
95 95 snoozed: HashSet<String>,
96 dismissed: HashSet<String>,
96 dismissed: HashMap<String, ReminderPhase>,
97 97 chimed: HashSet<String>,
98 98 next_id: u64,
99 99 last_check: Option<DateTime<Utc>>,
@@ -122,13 +122,26 @@ impl MeetingToasts {
122 122 &mut self.outlook
123 123 }
124 124
125 /// Closing a reminder keeps the meeting quiet until someone joins it, then the live toast still comes, like Teams.
125 126 pub fn dismiss(&mut self, id: u64) -> Option<MeetingToast> {
126 127 let index = self.entries.iter().position(|toast| toast.id == id)?;
127 128 let toast = self.entries.remove(index);
128 self.dismissed.insert(toast.event_key.clone());
129 self.dismissed.insert(toast.event_key.clone(), toast.phase);
129 130 Some(toast)
130 131 }
131 132
133 pub fn dismiss_for_good(&mut self, id: u64) -> Option<MeetingToast> {
134 let toast = self.dismiss(id)?;
135 self.dismissed.insert(toast.event_key.clone(), ReminderPhase::Live);
136 Some(toast)
137 }
138
139 fn blocked(&self, key: &str, phase: ReminderPhase) -> bool {
140 self.dismissed
141 .get(key)
142 .is_some_and(|dismissed_at| *dismissed_at == ReminderPhase::Live || phase != ReminderPhase::Live)
143 }
144
132 145 pub fn snooze(&mut self, id: u64) -> Option<MeetingToast> {
133 146 let index = self.entries.iter().position(|toast| toast.id == id)?;
134 147 let toast = self.entries.remove(index);
@@ -157,7 +170,7 @@ impl MeetingToasts {
157 170 let candidates: Vec<String> = events
158 171 .iter()
159 172 .filter(|event| {
160 phase_at(event, now, false).is_some() && !self.dismissed.contains(&event_key(event))
173 phase_at(event, now, false).is_some() && !self.blocked(&event_key(event), ReminderPhase::Live)
161 174 })
162 175 .filter_map(|event| event.thread_id.clone())
163 176 .collect();
@@ -179,15 +192,16 @@ impl MeetingToasts {
179 192 let outlook = &self.outlook;
180 193 self.entries.retain(|toast| {
181 194 events.iter().any(|event| {
195 let phase = phase_at(event, now, is_live(event, live_threads));
182 196 event_key(event) == toast.event_key
183 && outlook.allows(event, now)
184 && phase_at(event, now, is_live(event, live_threads)).is_some()
197 && phase.is_some()
198 && (phase == Some(ReminderPhase::Live) || outlook.allows(event, now))
185 199 })
186 200 });
187 201 let keys: HashSet<String> = events.iter().map(event_key).collect();
188 202 self.fired.retain(|(key, _)| keys.contains(key));
189 203 self.snoozed.retain(|key| keys.contains(key));
190 self.dismissed.retain(|key| keys.contains(key));
204 self.dismissed.retain(|key, _| keys.contains(key));
191 205 self.chimed.retain(|key| keys.contains(key));
192 206 let mut chime = false;
193 207 for event in events {
@@ -195,10 +209,10 @@ impl MeetingToasts {
195 209 continue;
196 210 };
197 211 let key = event_key(event);
198 if self.dismissed.contains(&key) {
212 if self.blocked(&key, phase) {
199 213 continue;
200 214 }
201 if !self.outlook.allows(event, now) {
215 if phase != ReminderPhase::Live && !self.outlook.allows(event, now) {
202 216 self.fired.retain(|(fired_key, _)| *fired_key != key);
203 217 continue;
204 218 }
@@ -285,7 +299,7 @@ impl AppState {
285 299 }
286 300
287 301 pub fn join_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
288 let Some(toast) = self.meeting_toasts.dismiss(id) else {
302 let Some(toast) = self.meeting_toasts.dismiss_for_good(id) else {
289 303 return;
290 304 };
291 305 cx.emit(AppEvent::MeetingReminder);
@@ -512,18 +526,6 @@ mod tests {
512 526 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Live);
513 527 }
514 528
515 #[test]
516 fn a_toast_closed_with_the_corner_x_stays_gone_when_the_meeting_goes_live() {
517 let events = [live_event("a")];
518 let mut toasts = MeetingToasts::default();
519 tick(&mut toasts, &events, at(8, 55, 0), true);
520 let id = toasts.entries()[0].id;
521 toasts.dismiss(id);
522 let update = tick_live(&mut toasts, &events, at(8, 57, 0));
523 assert!(!update.changed && !update.chime);
524 assert!(toasts.is_empty());
525 }
526
527 529 #[test]
528 530 fn started_then_live_chimes_once() {
529 531 let events = [live_event("a")];
@@ -594,7 +596,7 @@ mod tests {
594 596 tick(&mut toasts, &events, at(8, 56, 0), true);
595 597 let id = toasts.entries()[0].id;
596 598 toasts.dismiss(id);
597 assert!(toasts.live_candidates(&events, at(8, 57, 0)).is_empty());
599 assert_eq!(toasts.live_candidates(&events, at(8, 57, 0)).len(), 1);
598 600 }
599 601
600 602 #[test]
@@ -736,6 +738,38 @@ mod tests {
736 738 assert_eq!(dismissed.event_id, "b");
737 739 }
738 740
741 #[test]
742 fn a_closed_reminder_still_pops_up_once_someone_joins() {
743 let events = [live_event("a")];
744 let mut toasts = MeetingToasts::default();
745 tick(&mut toasts, &events, at(8, 55, 0), true);
746 toasts.dismiss(toasts.entries()[0].id);
747 assert!(!tick(&mut toasts, &events, at(9, 0, 0), true).changed);
748 assert!(tick_live(&mut toasts, &events, at(9, 2, 0)).changed);
749 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Live);
750 toasts.dismiss(toasts.entries()[0].id);
751 assert!(!tick_live(&mut toasts, &events, at(9, 3, 0)).changed);
752 }
753
754 #[test]
755 fn a_reminder_dismissed_in_outlook_does_not_mute_the_live_toast() {
756 let events = [live_event("a")];
757 let mut toasts = MeetingToasts::default();
758 outlook_state(&mut toasts, at(8, 54, 0), &[]);
759 assert!(!tick(&mut toasts, &events, at(8, 56, 0), true).changed);
760 assert!(tick_live(&mut toasts, &events, at(8, 57, 0)).changed);
761 }
762
763 #[test]
764 fn joining_from_the_reminder_mutes_the_live_toast() {
765 let events = [live_event("a")];
766 let mut toasts = MeetingToasts::default();
767 tick(&mut toasts, &events, at(8, 55, 0), true);
768 toasts.dismiss_for_good(toasts.entries()[0].id);
769 assert!(!tick_live(&mut toasts, &events, at(9, 2, 0)).changed);
770 assert!(toasts.live_candidates(&events, at(9, 2, 0)).is_empty());
771 }
772
739 773 #[test]
740 774 fn checks_run_at_most_once_a_second() {
741 775 let mut toasts = MeetingToasts::default();
@@ -1,4 +1,4 @@
1use std::collections::HashSet;
1use std::collections::{HashMap, HashSet};
2
2
3use chatsvc::{CalendarEvent, ResponseType};
3use chatsvc::{CalendarEvent, ResponseType};
4use chrono::{DateTime, Duration, FixedOffset, Utc};
4use chrono::{DateTime, Duration, FixedOffset, Utc};
@@ -93,7 +93,7 @@ pub struct MeetingToasts {
93 entries: Vec<MeetingToast>,
93 entries: Vec<MeetingToast>,
94 fired: HashSet<(String, ReminderPhase)>,
94 fired: HashSet<(String, ReminderPhase)>,
95 snoozed: HashSet<String>,
95 snoozed: HashSet<String>,
96 dismissed: HashSet<String>,
96 dismissed: HashMap<String, ReminderPhase>,
97 chimed: HashSet<String>,
97 chimed: HashSet<String>,
98 next_id: u64,
98 next_id: u64,
99 last_check: Option<DateTime<Utc>>,
99 last_check: Option<DateTime<Utc>>,
@@ -122,13 +122,26 @@ impl MeetingToasts {
122 &mut self.outlook
122 &mut self.outlook
123 }
123 }
124
124
125 /// Closing a reminder keeps the meeting quiet until someone joins it, then the live toast still comes, like Teams.
125 pub fn dismiss(&mut self, id: u64) -> Option<MeetingToast> {
126 pub fn dismiss(&mut self, id: u64) -> Option<MeetingToast> {
126 let index = self.entries.iter().position(|toast| toast.id == id)?;
127 let index = self.entries.iter().position(|toast| toast.id == id)?;
127 let toast = self.entries.remove(index);
128 let toast = self.entries.remove(index);
128 self.dismissed.insert(toast.event_key.clone());
129 self.dismissed.insert(toast.event_key.clone(), toast.phase);
129 Some(toast)
130 Some(toast)
130 }
131 }
131
132
133 pub fn dismiss_for_good(&mut self, id: u64) -> Option<MeetingToast> {
134 let toast = self.dismiss(id)?;
135 self.dismissed.insert(toast.event_key.clone(), ReminderPhase::Live);
136 Some(toast)
137 }
138
139 fn blocked(&self, key: &str, phase: ReminderPhase) -> bool {
140 self.dismissed
141 .get(key)
142 .is_some_and(|dismissed_at| *dismissed_at == ReminderPhase::Live || phase != ReminderPhase::Live)
143 }
144
132 pub fn snooze(&mut self, id: u64) -> Option<MeetingToast> {
145 pub fn snooze(&mut self, id: u64) -> Option<MeetingToast> {
133 let index = self.entries.iter().position(|toast| toast.id == id)?;
146 let index = self.entries.iter().position(|toast| toast.id == id)?;
134 let toast = self.entries.remove(index);
147 let toast = self.entries.remove(index);
@@ -157,7 +170,7 @@ impl MeetingToasts {
157 let candidates: Vec<String> = events
170 let candidates: Vec<String> = events
158 .iter()
171 .iter()
159 .filter(|event| {
172 .filter(|event| {
160 phase_at(event, now, false).is_some() && !self.dismissed.contains(&event_key(event))
173 phase_at(event, now, false).is_some() && !self.blocked(&event_key(event), ReminderPhase::Live)
161 })
174 })
162 .filter_map(|event| event.thread_id.clone())
175 .filter_map(|event| event.thread_id.clone())
163 .collect();
176 .collect();
@@ -179,15 +192,16 @@ impl MeetingToasts {
179 let outlook = &self.outlook;
192 let outlook = &self.outlook;
180 self.entries.retain(|toast| {
193 self.entries.retain(|toast| {
181 events.iter().any(|event| {
194 events.iter().any(|event| {
195 let phase = phase_at(event, now, is_live(event, live_threads));
182 event_key(event) == toast.event_key
196 event_key(event) == toast.event_key
183 && outlook.allows(event, now)
197 && phase.is_some()
184 && phase_at(event, now, is_live(event, live_threads)).is_some()
198 && (phase == Some(ReminderPhase::Live) || outlook.allows(event, now))
185 })
199 })
186 });
200 });
187 let keys: HashSet<String> = events.iter().map(event_key).collect();
201 let keys: HashSet<String> = events.iter().map(event_key).collect();
188 self.fired.retain(|(key, _)| keys.contains(key));
202 self.fired.retain(|(key, _)| keys.contains(key));
189 self.snoozed.retain(|key| keys.contains(key));
203 self.snoozed.retain(|key| keys.contains(key));
190 self.dismissed.retain(|key| keys.contains(key));
204 self.dismissed.retain(|key, _| keys.contains(key));
191 self.chimed.retain(|key| keys.contains(key));
205 self.chimed.retain(|key| keys.contains(key));
192 let mut chime = false;
206 let mut chime = false;
193 for event in events {
207 for event in events {
@@ -195,10 +209,10 @@ impl MeetingToasts {
195 continue;
209 continue;
196 };
210 };
197 let key = event_key(event);
211 let key = event_key(event);
198 if self.dismissed.contains(&key) {
212 if self.blocked(&key, phase) {
199 continue;
213 continue;
200 }
214 }
201 if !self.outlook.allows(event, now) {
215 if phase != ReminderPhase::Live && !self.outlook.allows(event, now) {
202 self.fired.retain(|(fired_key, _)| *fired_key != key);
216 self.fired.retain(|(fired_key, _)| *fired_key != key);
203 continue;
217 continue;
204 }
218 }
@@ -285,7 +299,7 @@ impl AppState {
285 }
299 }
286
300
287 pub fn join_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
301 pub fn join_meeting_toast(&mut self, id: u64, cx: &mut Context<Self>) {
288 let Some(toast) = self.meeting_toasts.dismiss(id) else {
302 let Some(toast) = self.meeting_toasts.dismiss_for_good(id) else {
289 return;
303 return;
290 };
304 };
291 cx.emit(AppEvent::MeetingReminder);
305 cx.emit(AppEvent::MeetingReminder);
@@ -512,18 +526,6 @@ mod tests {
512 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Live);
526 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Live);
513 }
527 }
514
528
515 #[test]
516 fn a_toast_closed_with_the_corner_x_stays_gone_when_the_meeting_goes_live() {
517 let events = [live_event("a")];
518 let mut toasts = MeetingToasts::default();
519 tick(&mut toasts, &events, at(8, 55, 0), true);
520 let id = toasts.entries()[0].id;
521 toasts.dismiss(id);
522 let update = tick_live(&mut toasts, &events, at(8, 57, 0));
523 assert!(!update.changed && !update.chime);
524 assert!(toasts.is_empty());
525 }
526
527 #[test]
529 #[test]
528 fn started_then_live_chimes_once() {
530 fn started_then_live_chimes_once() {
529 let events = [live_event("a")];
531 let events = [live_event("a")];
@@ -594,7 +596,7 @@ mod tests {
594 tick(&mut toasts, &events, at(8, 56, 0), true);
596 tick(&mut toasts, &events, at(8, 56, 0), true);
595 let id = toasts.entries()[0].id;
597 let id = toasts.entries()[0].id;
596 toasts.dismiss(id);
598 toasts.dismiss(id);
597 assert!(toasts.live_candidates(&events, at(8, 57, 0)).is_empty());
599 assert_eq!(toasts.live_candidates(&events, at(8, 57, 0)).len(), 1);
598 }
600 }
599
601
600 #[test]
602 #[test]
@@ -736,6 +738,38 @@ mod tests {
736 assert_eq!(dismissed.event_id, "b");
738 assert_eq!(dismissed.event_id, "b");
737 }
739 }
738
740
741 #[test]
742 fn a_closed_reminder_still_pops_up_once_someone_joins() {
743 let events = [live_event("a")];
744 let mut toasts = MeetingToasts::default();
745 tick(&mut toasts, &events, at(8, 55, 0), true);
746 toasts.dismiss(toasts.entries()[0].id);
747 assert!(!tick(&mut toasts, &events, at(9, 0, 0), true).changed);
748 assert!(tick_live(&mut toasts, &events, at(9, 2, 0)).changed);
749 assert_eq!(toasts.entries()[0].phase, ReminderPhase::Live);
750 toasts.dismiss(toasts.entries()[0].id);
751 assert!(!tick_live(&mut toasts, &events, at(9, 3, 0)).changed);
752 }
753
754 #[test]
755 fn a_reminder_dismissed_in_outlook_does_not_mute_the_live_toast() {
756 let events = [live_event("a")];
757 let mut toasts = MeetingToasts::default();
758 outlook_state(&mut toasts, at(8, 54, 0), &[]);
759 assert!(!tick(&mut toasts, &events, at(8, 56, 0), true).changed);
760 assert!(tick_live(&mut toasts, &events, at(8, 57, 0)).changed);
761 }
762
763 #[test]
764 fn joining_from_the_reminder_mutes_the_live_toast() {
765 let events = [live_event("a")];
766 let mut toasts = MeetingToasts::default();
767 tick(&mut toasts, &events, at(8, 55, 0), true);
768 toasts.dismiss_for_good(toasts.entries()[0].id);
769 assert!(!tick_live(&mut toasts, &events, at(9, 2, 0)).changed);
770 assert!(toasts.live_candidates(&events, at(9, 2, 0)).is_empty());
771 }
772
739 #[test]
773 #[test]
740 fn checks_run_at_most_once_a_second() {
774 fn checks_run_at_most_once_a_second() {
741 let mut toasts = MeetingToasts::default();
775 let mut toasts = MeetingToasts::default();