BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-state / src / call_rows.rs

call_rows.rs

call_rows.rs 26.8 KiB Download Raw
1use std::collections::{HashMap, HashSet};
2
3use chrono::{DateTime, FixedOffset, NaiveDate, Utc};
4use store::MessageRecord;
5use teams_core::roster_event::RosterEvent;
6use teams_core::{CallEvent, CallPhase, CallType, ImageRef, format_duration};
7
8use crate::format;
9
10const MAX_AVATARS: usize = 4;
11const RECAP_FALLBACK_TITLE: &str = "Meeting";
12const RECAP_DATE_FORMAT: &str = "%A, %-d %B %Y";
13const AUTO_STOP_SECONDS: i64 = 5;
14const WEEKDAY_STAMP_DAYS: i64 = 6;
15const OWN_NAME: &str = "You";
16const UNKNOWN_USER: &str = "Unknown User";
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum CallIcon {
20 Call,
21 Missed,
22 Video,
23 Record,
24 RecordStop,
25 Saved,
26 Roster,
27}
28
29#[derive(Debug, Clone, PartialEq, Eq)]
30pub struct CallParticipant {
31 pub user_id: String,
32 pub name: String,
33}
34
35#[derive(Debug, Clone, PartialEq, Eq)]
36pub struct RecordingCard {
37 pub message_id: String,
38 pub duration: Option<String>,
39 pub url: Option<String>,
40 pub thumbnail: Option<ImageRef>,
41 pub transcript: bool,
42 pub expires_in_days: Option<i64>,
43}
44
45/// The card Teams puts under the "Meeting ended" line of a meeting with a recording.
46#[derive(Debug, Clone, PartialEq, Eq)]
47pub struct RecapCard {
48 pub title: String,
49 pub date_line: String,
50 pub recording: RecordingCard,
51}
52
53/// A meeting or recording event as Teams draws it: one muted line, icon in the avatar column.
54#[derive(Debug, Clone, PartialEq, Eq)]
55pub struct CallNotice {
56 pub stamp: String,
57 pub text: String,
58 pub emphasis: Option<String>,
59}
60
61#[derive(Debug, Clone, PartialEq, Eq)]
62pub struct CallCard {
63 pub title: String,
64 pub detail: String,
65 pub icon: CallIcon,
66 pub missed: bool,
67 pub started: bool,
68 pub participants: Vec<CallParticipant>,
69 pub extra_participants: usize,
70 pub notice: Option<CallNotice>,
71 pub recap: Option<RecapCard>,
72}
73
74#[derive(Debug, Clone, Copy, PartialEq, Eq)]
75pub struct MeetingSlot {
76 pub start: DateTime<Utc>,
77 pub end: DateTime<Utc>,
78}
79
80/// What the meeting rows need beyond the messages: the chat topic, the calendar occurrences
81/// and the recording expiry the Recap tab reads, keyed by the saved recording message id.
82#[derive(Debug, Clone, Default, PartialEq)]
83pub struct MeetingInfo {
84 pub title: Option<String>,
85 pub slots: Vec<MeetingSlot>,
86 pub expiry_days: HashMap<String, i64>,
87}
88
89pub struct CallNames<'a> {
90 pub my_user_id: Option<&'a str>,
91 pub names: &'a HashMap<String, String>,
92}
93
94impl CallNames<'_> {
95 fn name(&self, user_id: Option<&str>, given: Option<&str>) -> Option<String> {
96 given
97 .filter(|name| !name.is_empty())
98 .map(str::to_owned)
99 .or_else(|| self.names.get(user_id?).cloned())
100 }
101
102 fn roster_name(&self, user_id: Option<&str>, given: Option<&str>) -> String {
103 if user_id.is_some() && user_id == self.my_user_id {
104 return OWN_NAME.to_owned();
105 }
106 self.name(user_id, given)
107 .unwrap_or_else(|| UNKNOWN_USER.to_owned())
108 }
109}
110
111/// A member added, removed or leaving: one muted line with the people icon, like Teams.
112pub fn roster_card(
113 event: &RosterEvent,
114 created_at: DateTime<Utc>,
115 names: &CallNames,
116 clock: &CallClock,
117) -> CallCard {
118 CallCard {
119 title: String::new(),
120 detail: String::new(),
121 icon: CallIcon::Roster,
122 missed: false,
123 started: false,
124 participants: Vec::new(),
125 extra_participants: 0,
126 notice: Some(CallNotice {
127 stamp: notice_stamp(created_at, clock),
128 text: event.text(|user_id, given| names.roster_name(user_id, given)),
129 emphasis: None,
130 }),
131 recap: None,
132 }
133}
134
135pub struct CallClock<'a> {
136 pub offset: FixedOffset,
137 pub today: NaiveDate,
138 pub meeting: &'a MeetingInfo,
139}
140
141struct SavedRecording {
142 message_id: String,
143 event: CallEvent,
144}
145
146/// Which call events of a timeline show as rows: Teams keeps one row per recording start and stop,
147/// hides transcript notices and, for calls (not meetings), the start once the call ended.
148pub struct CallTimeline {
149 hidden: Vec<bool>,
150 finished: HashSet<String>,
151 transcripts: HashSet<String>,
152 newest_open_start: Option<usize>,
153 started_at: HashMap<String, DateTime<Utc>>,
154 ended_at: HashMap<String, DateTime<Utc>>,
155 saved: HashMap<String, SavedRecording>,
156}
157
158impl CallTimeline {
159 pub fn new(events: &[Option<CallEvent>]) -> Self {
160 Self::with_records(events, &[])
161 }
162
163 pub fn with_records(events: &[Option<CallEvent>], records: &[&MessageRecord]) -> Self {
164 let finished: HashSet<String> = events
165 .iter()
166 .flatten()
167 .filter(|event| event.phase == CallPhase::Ended)
168 .map(|event| event.call_id.clone())
169 .collect();
170 let transcripts: HashSet<String> = events
171 .iter()
172 .flatten()
173 .filter(|event| event.phase == CallPhase::TranscriptStarted)
174 .map(|event| event.call_id.clone())
175 .collect();
176 let mut shown_once: HashSet<(String, CallPhase)> = HashSet::new();
177 let hidden = events
178 .iter()
179 .map(|event| {
180 let Some(event) = event else {
181 return false;
182 };
183 match event.phase {
184 CallPhase::TranscriptStarted => true,
185 CallPhase::RecordingStarted | CallPhase::RecordingStopped => {
186 !shown_once.insert((event.call_id.clone(), event.phase))
187 }
188 CallPhase::Started => {
189 event.call_type == CallType::Call && finished.contains(&event.call_id)
190 }
191 _ => false,
192 }
193 })
194 .collect();
195 let newest_open_start = events.iter().rposition(|event| {
196 event.as_ref().is_some_and(|event| {
197 event.phase == CallPhase::Started && !finished.contains(&event.call_id)
198 })
199 });
200 let mut started_at = HashMap::new();
201 let mut ended_at = HashMap::new();
202 let mut saved = HashMap::new();
203 for (event, record) in events.iter().zip(records) {
204 let Some(event) = event else {
205 continue;
206 };
207 match event.phase {
208 CallPhase::Started => {
209 started_at
210 .entry(event.call_id.clone())
211 .or_insert(record.created_at);
212 }
213 CallPhase::Ended => {
214 ended_at.insert(event.call_id.clone(), record.created_at);
215 }
216 CallPhase::RecordingSaved => {
217 saved.insert(
218 event.call_id.clone(),
219 SavedRecording {
220 message_id: record.message_id.clone(),
221 event: event.clone(),
222 },
223 );
224 }
225 _ => {}
226 }
227 }
228 CallTimeline {
229 hidden,
230 finished,
231 transcripts,
232 newest_open_start,
233 started_at,
234 ended_at,
235 saved,
236 }
237 }
238
239 pub fn hides(&self, index: usize) -> bool {
240 self.hidden.get(index).copied().unwrap_or(false)
241 }
242
243 pub fn is_live_start(&self, index: usize) -> bool {
244 self.newest_open_start == Some(index)
245 }
246
247 pub fn finished(&self, call_id: &str) -> bool {
248 self.finished.contains(call_id)
249 }
250
251 pub fn has_transcript(&self, call_id: &str) -> bool {
252 self.transcripts.contains(call_id)
253 }
254
255 /// A recording that stops with the meeting end has no one who stopped it; Teams then says
256 /// "Recording stopped." instead of naming the recorder.
257 fn stopped_by_meeting_end(&self, event: &CallEvent, created_at: DateTime<Utc>) -> bool {
258 self.ended_at.get(&event.call_id).is_some_and(|ended_at| {
259 (*ended_at - created_at).num_seconds().abs() <= AUTO_STOP_SECONDS
260 })
261 }
262
263 fn recap(
264 &self,
265 ended: &CallEvent,
266 ended_at: DateTime<Utc>,
267 clock: &CallClock,
268 ) -> Option<RecapCard> {
269 if ended.phase != CallPhase::Ended || ended.call_type != CallType::Meeting {
270 return None;
271 }
272 let saved = self.saved.get(&ended.call_id)?;
273 let started_at = self
274 .started_at
275 .get(&ended.call_id)
276 .copied()
277 .or_else(|| {
278 ended
279 .duration_seconds
280 .map(|seconds| ended_at - chrono::Duration::seconds(seconds as i64))
281 })
282 .unwrap_or(ended_at);
283 let recording = recording_card(
284 &saved.event,
285 &saved.message_id,
286 self.has_transcript(&ended.call_id),
287 clock.meeting,
288 )?;
289 let title = clock
290 .meeting
291 .title
292 .clone()
293 .filter(|title| !title.trim().is_empty())
294 .or_else(|| saved.event.recording.as_ref()?.title())
295 .unwrap_or_else(|| RECAP_FALLBACK_TITLE.to_owned());
296 Some(RecapCard {
297 title,
298 date_line: recap_date_line(started_at, ended_at, clock),
299 recording,
300 })
301 }
302}
303
304/// Teams dates the recap card with the scheduled occurrence; without a calendar match the call's
305/// own start and end stand in.
306fn recap_date_line(
307 started_at: DateTime<Utc>,
308 ended_at: DateTime<Utc>,
309 clock: &CallClock,
310) -> String {
311 let slot = clock
312 .meeting
313 .slots
314 .iter()
315 .filter(|slot| slot.start <= ended_at && slot.end >= started_at)
316 .min_by_key(|slot| (slot.start - started_at).num_seconds().abs())
317 .copied()
318 .unwrap_or(MeetingSlot {
319 start: started_at,
320 end: ended_at,
321 });
322 format!(
323 "{} - {}",
324 slot.start
325 .with_timezone(&clock.offset)
326 .format(&format!("{RECAP_DATE_FORMAT} {}", app_base::format::clock_format())),
327 slot.end
328 .with_timezone(&clock.offset)
329 .format(app_base::format::clock_format())
330 )
331}
332
333/// Teams writes the weekday in full on these lines ("Thursday 11:45"), unlike message times.
334fn notice_stamp(time: DateTime<Utc>, clock: &CallClock) -> String {
335 let local = time.with_timezone(&clock.offset);
336 let days_ago = (clock.today - local.date_naive()).num_days();
337 if (2..=WEEKDAY_STAMP_DAYS).contains(&days_ago) {
338 format!(
339 "{} {}",
340 local.format("%A"),
341 local.format(app_base::format::clock_format())
342 )
343 } else {
344 format::post_time_label(time, clock.today, clock.offset)
345 }
346}
347
348fn participants(event: &CallEvent, names: &CallNames) -> Vec<CallParticipant> {
349 event
350 .participant_ids
351 .iter()
352 .enumerate()
353 .filter_map(|(index, user_id)| {
354 let given = event.participant_names.get(index).map(String::as_str);
355 Some(CallParticipant {
356 user_id: user_id.clone(),
357 name: names.name(Some(user_id), given)?,
358 })
359 })
360 .collect()
361}
362
363fn recording_card(
364 event: &CallEvent,
365 message_id: &str,
366 transcript: bool,
367 meeting: &MeetingInfo,
368) -> Option<RecordingCard> {
369 let recording = event.recording.as_ref()?;
370 Some(RecordingCard {
371 message_id: message_id.to_owned(),
372 duration: event
373 .duration_seconds
374 .filter(|seconds| *seconds > 0)
375 .map(format_duration),
376 url: recording.url.clone(),
377 thumbnail: recording.thumbnail_url().map(|url| ImageRef {
378 id: format!("recording-{message_id}"),
379 url,
380 width: None,
381 height: None,
382 alt: None,
383 }),
384 transcript,
385 expires_in_days: meeting.expiry_days.get(message_id).copied(),
386 })
387}
388
389fn day_count(days: i64) -> String {
390 if days == 1 {
391 "1 day".to_owned()
392 } else {
393 format!("{days} days")
394 }
395}
396
397struct NoticeSource<'a> {
398 event: &'a CallEvent,
399 message_id: &'a str,
400 stopped_by_meeting_end: bool,
401}
402
403fn notice_text(source: NoticeSource, names: &CallNames, meeting: &MeetingInfo) -> String {
404 let NoticeSource {
405 event,
406 message_id,
407 stopped_by_meeting_end,
408 } = source;
409 let initiator = || {
410 names.name(
411 event.initiator_id.as_deref(),
412 event.initiator_name.as_deref(),
413 )
414 };
415 match event.phase {
416 CallPhase::Ended => format!("{}:", event.title(false)),
417 CallPhase::RecordingStarted => match initiator() {
418 Some(name) => format!("{name} started recording."),
419 None => event.title(false).to_owned(),
420 },
421 CallPhase::RecordingStopped => match initiator().filter(|_| !stopped_by_meeting_end) {
422 Some(name) => format!("{name} stopped recording."),
423 None => format!("{}.", event.title(false)),
424 },
425 CallPhase::RecordingSaved => {
426 let saved = saved_to(event, names);
427 match meeting.expiry_days.get(message_id) {
428 Some(days) => format!("{saved} and will expire in {}.", day_count(*days)),
429 None => format!("{saved}."),
430 }
431 }
432 _ => event.title(false).to_owned(),
433 }
434}
435
436fn saved_to(event: &CallEvent, names: &CallNames) -> String {
437 let organizer_id = event
438 .recording
439 .as_ref()
440 .and_then(|recording| recording.organizer_id.as_deref());
441 if organizer_id.is_some() && organizer_id == names.my_user_id {
442 return "Recording has been saved to your OneDrive".to_owned();
443 }
444 match names.name(organizer_id, None) {
445 Some(owner) => format!("Recording has been saved to {owner}'s OneDrive"),
446 None => "Recording has been saved to OneDrive".to_owned(),
447 }
448}
449
450fn title(event: &CallEvent, missed: bool, names: &CallNames) -> String {
451 match event.phase {
452 CallPhase::RecordingStarted => {
453 match names.name(
454 event.initiator_id.as_deref(),
455 event.initiator_name.as_deref(),
456 ) {
457 Some(name) => format!("{name} started recording"),
458 None => event.title(false).to_owned(),
459 }
460 }
461 CallPhase::RecordingSaved => saved_to(event, names),
462 _ => event.title(missed).to_owned(),
463 }
464}
465
466/// Teams draws meeting and recording events as one-line notices; 1:1 and group calls keep the card.
467pub fn is_notice(event: &CallEvent) -> bool {
468 event.call_type == CallType::Meeting || event.is_recording()
469}
470
471pub struct CallSource<'a> {
472 pub event: &'a CallEvent,
473 pub message_id: &'a str,
474 pub created_at: DateTime<Utc>,
475 pub time: &'a str,
476}
477
478pub fn call_card(
479 source: CallSource,
480 names: &CallNames,
481 clock: &CallClock,
482 timeline: &CallTimeline,
483) -> CallCard {
484 let CallSource {
485 event,
486 message_id,
487 created_at,
488 time,
489 } = source;
490 let missed = event.missed(names.my_user_id);
491 let detail = match (event.phase, event.duration_seconds) {
492 (CallPhase::Ended, Some(seconds)) if !missed => {
493 format!("{} \u{b7} {time}", format_duration(seconds))
494 }
495 _ => time.to_owned(),
496 };
497 let mut people = if event.phase == CallPhase::Ended && event.call_type == CallType::Meeting {
498 participants(event, names)
499 } else {
500 Vec::new()
501 };
502 let extra_participants = people.len().saturating_sub(MAX_AVATARS);
503 people.truncate(MAX_AVATARS);
504 let notice = is_notice(event).then(|| CallNotice {
505 stamp: notice_stamp(created_at, clock),
506 text: notice_text(
507 NoticeSource {
508 event,
509 message_id,
510 stopped_by_meeting_end: timeline.stopped_by_meeting_end(event, created_at),
511 },
512 names,
513 clock.meeting,
514 ),
515 emphasis: event
516 .duration_seconds
517 .filter(|_| event.phase == CallPhase::Ended)
518 .map(format_duration),
519 });
520 CallCard {
521 title: title(event, missed, names),
522 detail,
523 icon: match (missed, event.phase, event.call_type) {
524 (true, _, _) => CallIcon::Missed,
525 (false, CallPhase::RecordingStarted, _) => CallIcon::Record,
526 (false, CallPhase::RecordingSaved, _) => CallIcon::Saved,
527 (false, CallPhase::RecordingStopped | CallPhase::TranscriptStarted, _) => {
528 CallIcon::RecordStop
529 }
530 (false, _, CallType::Meeting) => CallIcon::Video,
531 (false, _, CallType::Call) => CallIcon::Call,
532 },
533 missed,
534 started: event.phase == CallPhase::Started,
535 participants: people,
536 extra_participants,
537 recap: timeline.recap(event, created_at, clock),
538 notice,
539 }
540}
541
542#[cfg(test)]
543mod tests {
544 use chrono::TimeZone;
545 use teams_core::Recording;
546
547 use super::*;
548
549 fn event(phase: CallPhase, call_type: CallType, call_id: &str) -> CallEvent {
550 CallEvent {
551 phase,
552 call_type,
553 call_id: call_id.to_owned(),
554 duration_seconds: None,
555 initiator_id: Some("organizer".to_owned()),
556 initiator_name: None,
557 participant_ids: Vec::new(),
558 participant_names: Vec::new(),
559 recording: None,
560 }
561 }
562
563 fn fixture_records() -> Vec<MessageRecord> {
564 let path = format!(
565 "{}/../core/tests/fixtures/call_events/meeting_chat_recording.json",
566 env!("CARGO_MANIFEST_DIR")
567 );
568 let page: serde_json::Value =
569 serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap();
570 page["value"]
571 .as_array()
572 .unwrap()
573 .iter()
574 .rev()
575 .map(|message| {
576 let message: graph::Message = serde_json::from_value(message.clone()).unwrap();
577 teams_core::message_record("meeting-chat", &message).unwrap()
578 })
579 .collect()
580 }
581
582 fn names() -> HashMap<String, String> {
583 HashMap::from([
584 (
585 "00000000-0000-4000-8000-000000000002".to_owned(),
586 "Vera Organizer".to_owned(),
587 ),
588 (
589 "00000000-0000-4000-8000-000000000004".to_owned(),
590 "Sam Recorder".to_owned(),
591 ),
592 ])
593 }
594
595 fn cards(records: &[MessageRecord], meeting: &MeetingInfo) -> Vec<CallCard> {
596 let events: Vec<Option<CallEvent>> = records.iter().map(teams_core::call_event).collect();
597 let timeline = CallTimeline::with_records(&events, &records.iter().collect::<Vec<_>>());
598 let names = names();
599 let lookup = CallNames {
600 my_user_id: Some("me"),
601 names: &names,
602 };
603 let clock = CallClock {
604 offset: FixedOffset::east_opt(0).unwrap(),
605 today: NaiveDate::from_ymd_opt(2026, 10, 30).unwrap(),
606 meeting,
607 };
608 events
609 .iter()
610 .zip(records)
611 .enumerate()
612 .filter(|(index, _)| !timeline.hides(*index))
613 .map(|(_, (event, record))| {
614 call_card(
615 CallSource {
616 event: event.as_ref().unwrap(),
617 message_id: &record.message_id,
618 created_at: record.created_at,
619 time: "16:15",
620 },
621 &lookup,
622 &clock,
623 &timeline,
624 )
625 })
626 .collect()
627 }
628
629 fn notice_line(card: &CallCard) -> String {
630 let notice = card.notice.as_ref().unwrap();
631 match &notice.emphasis {
632 Some(emphasis) => format!("{} {emphasis}", notice.text),
633 None => notice.text.clone(),
634 }
635 }
636
637 #[test]
638 fn recorded_meeting_shows_as_teams_notices() {
639 let shown = cards(&fixture_records(), &MeetingInfo::default());
640 let lines: Vec<String> = shown.iter().map(notice_line).collect();
641 assert_eq!(
642 lines,
643 [
644 "Meeting started",
645 "Sam Recorder started recording.",
646 "Recording stopped.",
647 "Meeting ended: 16m 28s",
648 "Recording has been saved to Vera Organizer's OneDrive.",
649 ]
650 );
651 let icons: Vec<CallIcon> = shown.iter().map(|card| card.icon).collect();
652 assert_eq!(
653 icons,
654 [
655 CallIcon::Video,
656 CallIcon::Record,
657 CallIcon::RecordStop,
658 CallIcon::Video,
659 CallIcon::Saved,
660 ]
661 );
662 assert!(
663 shown
664 .iter()
665 .all(|card| card.recap.is_none() == (card.title != "Meeting ended"))
666 );
667 }
668
669 #[test]
670 fn a_recording_stopped_before_the_end_names_who_stopped_it() {
671 let mut records = fixture_records();
672 for record in records.iter_mut() {
673 if teams_core::call_event(record)
674 .is_some_and(|event| event.phase == CallPhase::RecordingStopped)
675 {
676 record.created_at -= chrono::Duration::minutes(2);
677 }
678 }
679 let shown = cards(&records, &MeetingInfo::default());
680 assert_eq!(notice_line(&shown[2]), "Sam Recorder stopped recording.");
681 }
682
683 #[test]
684 fn ended_meeting_carries_the_recap_card_of_its_recording() {
685 let records = fixture_records();
686 let saved_id = records.last().unwrap().message_id.clone();
687 let meeting = MeetingInfo {
688 title: Some("Weekly sync".to_owned()),
689 slots: Vec::new(),
690 expiry_days: HashMap::from([(saved_id.clone(), 56)]),
691 };
692 let shown = cards(&records, &meeting);
693 let ended = shown
694 .iter()
695 .find(|card| card.title == "Meeting ended")
696 .unwrap();
697 let recap = ended.recap.as_ref().unwrap();
698 assert_eq!(recap.title, "Weekly sync");
699 assert_eq!(recap.recording.message_id, saved_id);
700 assert_eq!(recap.recording.duration.as_deref(), Some("13m 34s"));
701 assert_eq!(recap.recording.expires_in_days, Some(56));
702 assert!(recap.recording.transcript);
703 assert!(
704 recap
705 .recording
706 .thumbnail
707 .as_ref()
708 .unwrap()
709 .url
710 .contains("/thumbnails/")
711 );
712 assert!(shown.iter().filter(|card| card.recap.is_some()).count() == 1);
713 assert_eq!(
714 notice_line(shown.last().unwrap()),
715 "Recording has been saved to Vera Organizer's OneDrive and will expire in 56 days."
716 );
717 }
718
719 #[test]
720 fn recap_date_prefers_the_calendar_occurrence() {
721 let started_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 46, 0).unwrap();
722 let ended_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 55, 0).unwrap();
723 let mut meeting = MeetingInfo::default();
724 let clock = |meeting: &MeetingInfo| {
725 recap_date_line(
726 started_at,
727 ended_at,
728 &CallClock {
729 offset: FixedOffset::east_opt(2 * 3600).unwrap(),
730 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
731 meeting,
732 },
733 )
734 };
735 assert_eq!(clock(&meeting), "Thursday, 15 October 2026 11:46 - 11:55");
736 meeting.slots = vec![
737 MeetingSlot {
738 start: Utc.with_ymd_and_hms(2026, 10, 14, 9, 45, 0).unwrap(),
739 end: Utc.with_ymd_and_hms(2026, 10, 14, 10, 0, 0).unwrap(),
740 },
741 MeetingSlot {
742 start: Utc.with_ymd_and_hms(2026, 10, 15, 9, 45, 0).unwrap(),
743 end: Utc.with_ymd_and_hms(2026, 10, 15, 10, 0, 0).unwrap(),
744 },
745 ];
746 assert_eq!(clock(&meeting), "Thursday, 15 October 2026 11:45 - 12:00");
747 }
748
749 #[test]
750 fn notice_stamps_spell_out_the_weekday_like_teams() {
751 let meeting = MeetingInfo::default();
752 let clock = CallClock {
753 offset: FixedOffset::east_opt(0).unwrap(),
754 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
755 meeting: &meeting,
756 };
757 let stamp = |day: u32| {
758 notice_stamp(
759 Utc.with_ymd_and_hms(2026, 10, day, 11, 45, 0).unwrap(),
760 &clock,
761 )
762 };
763 assert_eq!(stamp(17), "11:45");
764 assert_eq!(stamp(16), "Yesterday 11:45");
765 assert_eq!(stamp(15), "Thursday 11:45");
766 }
767
768 #[test]
769 fn ended_meeting_lists_named_participants_up_to_four() {
770 let shown = cards(&fixture_records(), &MeetingInfo::default());
771 let ended = shown
772 .iter()
773 .find(|card| card.title == "Meeting ended")
774 .unwrap();
775 assert_eq!(ended.detail, "16m 28s \u{b7} 16:15");
776 let shown_names: Vec<&str> = ended
777 .participants
778 .iter()
779 .map(|person| person.name.as_str())
780 .collect();
781 assert_eq!(
782 shown_names,
783 ["Person 1", "Person 2", "Person 3", "Person 4"]
784 );
785 assert_eq!(ended.extra_participants, 20);
786 }
787
788 #[test]
789 fn meeting_start_stays_but_a_finished_call_start_hides() {
790 let events = vec![
791 Some(event(CallPhase::Started, CallType::Meeting, "meeting")),
792 Some(event(CallPhase::Ended, CallType::Meeting, "meeting")),
793 Some(event(CallPhase::Started, CallType::Call, "call")),
794 Some(event(CallPhase::Ended, CallType::Call, "call")),
795 Some(event(CallPhase::Started, CallType::Meeting, "live")),
796 None,
797 ];
798 let timeline = CallTimeline::new(&events);
799 assert!(!timeline.hides(0));
800 assert!(timeline.hides(2));
801 assert!(!timeline.hides(5));
802 assert!(timeline.is_live_start(4));
803 assert!(!timeline.is_live_start(0));
804 assert!(timeline.finished("meeting"));
805 }
806
807 #[test]
808 fn calls_keep_their_card_and_my_recording_is_in_my_onedrive() {
809 assert!(!is_notice(&event(CallPhase::Ended, CallType::Call, "c")));
810 let mut saved = event(CallPhase::RecordingSaved, CallType::Call, "c");
811 saved.recording = Some(Recording {
812 name: None,
813 url: Some("https://contoso.example/rec.mp4".to_owned()),
814 organizer_id: Some("me".to_owned()),
815 });
816 let names = HashMap::new();
817 let lookup = CallNames {
818 my_user_id: Some("me"),
819 names: &names,
820 };
821 assert_eq!(
822 notice_text(
823 NoticeSource {
824 event: &saved,
825 message_id: "m",
826 stopped_by_meeting_end: false,
827 },
828 &lookup,
829 &MeetingInfo::default()
830 ),
831 "Recording has been saved to your OneDrive."
832 );
833 }
834}