BlueGit

ict rusty-teams

Files

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

call_rows.rs

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