BlueGit

ict rusty-teams

Files

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

call_rows.rs

chore: cargo fmt the workspace
metis Daniel Däschle · pushed by metis · 2 weeks ago
a6592765 History
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.with_timezone(&clock.offset).format(&format!(
326 "{RECAP_DATE_FORMAT} {}",
327 app_base::format::clock_format()
328 )),
329 slot.end
330 .with_timezone(&clock.offset)
331 .format(app_base::format::clock_format())
332 )
333}
334
335/// Teams writes the weekday in full on these lines ("Thursday 11:45"), unlike message times.
336fn notice_stamp(time: DateTime<Utc>, clock: &CallClock) -> String {
337 let local = time.with_timezone(&clock.offset);
338 let days_ago = (clock.today - local.date_naive()).num_days();
339 if (2..=WEEKDAY_STAMP_DAYS).contains(&days_ago) {
340 format!(
341 "{} {}",
342 local.format("%A"),
343 local.format(app_base::format::clock_format())
344 )
345 } else {
346 format::post_time_label(time, clock.today, clock.offset)
347 }
348}
349
350fn participants(event: &CallEvent, names: &CallNames) -> Vec<CallParticipant> {
351 event
352 .participant_ids
353 .iter()
354 .enumerate()
355 .filter_map(|(index, user_id)| {
356 let given = event.participant_names.get(index).map(String::as_str);
357 Some(CallParticipant {
358 user_id: user_id.clone(),
359 name: names.name(Some(user_id), given)?,
360 })
361 })
362 .collect()
363}
364
365fn recording_card(
366 event: &CallEvent,
367 message_id: &str,
368 transcript: bool,
369 meeting: &MeetingInfo,
370) -> Option<RecordingCard> {
371 let recording = event.recording.as_ref()?;
372 Some(RecordingCard {
373 message_id: message_id.to_owned(),
374 duration: event
375 .duration_seconds
376 .filter(|seconds| *seconds > 0)
377 .map(format_duration),
378 url: recording.url.clone(),
379 thumbnail: recording.thumbnail_url().map(|url| ImageRef {
380 id: format!("recording-{message_id}"),
381 url,
382 width: None,
383 height: None,
384 alt: None,
385 }),
386 transcript,
387 expires_in_days: meeting.expiry_days.get(message_id).copied(),
388 })
389}
390
391fn day_count(days: i64) -> String {
392 if days == 1 {
393 "1 day".to_owned()
394 } else {
395 format!("{days} days")
396 }
397}
398
399struct NoticeSource<'a> {
400 event: &'a CallEvent,
401 message_id: &'a str,
402 missed: bool,
403 stopped_by_meeting_end: bool,
404}
405
406fn notice_text(source: NoticeSource, names: &CallNames, meeting: &MeetingInfo) -> String {
407 let NoticeSource {
408 event,
409 message_id,
410 missed,
411 stopped_by_meeting_end,
412 } = source;
413 let initiator = || {
414 names.name(
415 event.initiator_id.as_deref(),
416 event.initiator_name.as_deref(),
417 )
418 };
419 match (event.phase, event.call_type) {
420 _ if missed => MISSED_CALL_NOTICE.to_owned(),
421 (CallPhase::Ended, CallType::Meeting) => format!("{}:", event.title(false)),
422 (CallPhase::Ended, CallType::Call) => event.title(false).to_owned(),
423 (CallPhase::RecordingStarted, _) => match initiator() {
424 Some(name) => format!("{name} started recording."),
425 None => event.title(false).to_owned(),
426 },
427 (CallPhase::RecordingStopped, _) => match initiator().filter(|_| !stopped_by_meeting_end) {
428 Some(name) => format!("{name} stopped recording."),
429 None => format!("{}.", event.title(false)),
430 },
431 (CallPhase::RecordingSaved, _) => {
432 let saved = saved_to(event, names);
433 match meeting.expiry_days.get(message_id) {
434 Some(days) => format!("{saved} and will expire in {}.", day_count(*days)),
435 None => format!("{saved}."),
436 }
437 }
438 _ => event.title(false).to_owned(),
439 }
440}
441
442fn saved_to(event: &CallEvent, names: &CallNames) -> String {
443 let organizer_id = event
444 .recording
445 .as_ref()
446 .and_then(|recording| recording.organizer_id.as_deref());
447 if organizer_id.is_some() && organizer_id == names.my_user_id {
448 return "Recording has been saved to your OneDrive".to_owned();
449 }
450 match names.name(organizer_id, None) {
451 Some(owner) => format!("Recording has been saved to {owner}'s OneDrive"),
452 None => "Recording has been saved to OneDrive".to_owned(),
453 }
454}
455
456fn title(event: &CallEvent, missed: bool, names: &CallNames) -> String {
457 match event.phase {
458 CallPhase::RecordingStarted => {
459 match names.name(
460 event.initiator_id.as_deref(),
461 event.initiator_name.as_deref(),
462 ) {
463 Some(name) => format!("{name} started recording"),
464 None => event.title(false).to_owned(),
465 }
466 }
467 CallPhase::RecordingSaved => saved_to(event, names),
468 _ => event.title(missed).to_owned(),
469 }
470}
471
472pub struct CallSource<'a> {
473 pub event: &'a CallEvent,
474 pub message_id: &'a str,
475 pub created_at: DateTime<Utc>,
476 pub time: &'a str,
477}
478
479pub fn call_card(
480 source: CallSource,
481 names: &CallNames,
482 clock: &CallClock,
483 timeline: &CallTimeline,
484) -> CallCard {
485 let CallSource {
486 event,
487 message_id,
488 created_at,
489 time,
490 } = source;
491 let missed = event.missed(names.my_user_id);
492 let detail = match (event.phase, event.duration_seconds) {
493 (CallPhase::Ended, Some(seconds)) if !missed => {
494 format!("{} \u{b7} {time}", format_duration(seconds))
495 }
496 _ => time.to_owned(),
497 };
498 let mut people = if event.phase == CallPhase::Ended && event.call_type == CallType::Meeting {
499 participants(event, names)
500 } else {
501 Vec::new()
502 };
503 let extra_participants = people.len().saturating_sub(MAX_AVATARS);
504 people.truncate(MAX_AVATARS);
505 let notice = CallNotice {
506 stamp: notice_stamp(created_at, clock),
507 text: notice_text(
508 NoticeSource {
509 event,
510 message_id,
511 missed,
512 stopped_by_meeting_end: timeline.stopped_by_meeting_end(event, created_at),
513 },
514 names,
515 clock.meeting,
516 ),
517 emphasis: event
518 .duration_seconds
519 .filter(|_| event.phase == CallPhase::Ended && !missed)
520 .map(format_duration),
521 };
522 CallCard {
523 title: title(event, missed, names),
524 detail,
525 icon: match (missed, event.phase, event.call_type) {
526 (true, _, _) => CallIcon::Missed,
527 (false, CallPhase::RecordingStarted, _) => CallIcon::Record,
528 (false, CallPhase::RecordingSaved, _) => CallIcon::Saved,
529 (false, CallPhase::RecordingStopped | CallPhase::TranscriptStarted, _) => {
530 CallIcon::RecordStop
531 }
532 (false, _, CallType::Meeting) => CallIcon::Video,
533 (false, _, CallType::Call) => CallIcon::Call,
534 },
535 missed,
536 started: event.phase == CallPhase::Started,
537 participants: people,
538 extra_participants,
539 recap: timeline.recap(event, created_at, clock),
540 notice,
541 }
542}
543
544#[cfg(test)]
545mod tests {
546 use chrono::TimeZone;
547 use teams_core::Recording;
548
549 use super::*;
550
551 fn event(phase: CallPhase, call_type: CallType, call_id: &str) -> CallEvent {
552 CallEvent {
553 phase,
554 call_type,
555 call_id: call_id.to_owned(),
556 duration_seconds: None,
557 initiator_id: Some("organizer".to_owned()),
558 initiator_name: None,
559 participant_ids: Vec::new(),
560 participant_names: Vec::new(),
561 recording: None,
562 }
563 }
564
565 fn fixture_records() -> Vec<MessageRecord> {
566 let path = format!(
567 "{}/../core/tests/fixtures/call_events/meeting_chat_recording.json",
568 env!("CARGO_MANIFEST_DIR")
569 );
570 let page: serde_json::Value =
571 serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap();
572 page["value"]
573 .as_array()
574 .unwrap()
575 .iter()
576 .rev()
577 .map(|message| {
578 let message: graph::Message = serde_json::from_value(message.clone()).unwrap();
579 teams_core::message_record("meeting-chat", &message).unwrap()
580 })
581 .collect()
582 }
583
584 fn names() -> HashMap<String, String> {
585 HashMap::from([
586 (
587 "00000000-0000-4000-8000-000000000002".to_owned(),
588 "Vera Organizer".to_owned(),
589 ),
590 (
591 "00000000-0000-4000-8000-000000000004".to_owned(),
592 "Sam Recorder".to_owned(),
593 ),
594 ])
595 }
596
597 fn cards(records: &[MessageRecord], meeting: &MeetingInfo) -> Vec<CallCard> {
598 let events: Vec<Option<CallEvent>> = records.iter().map(teams_core::call_event).collect();
599 let timeline = CallTimeline::with_records(&events, &records.iter().collect::<Vec<_>>());
600 let names = names();
601 let lookup = CallNames {
602 my_user_id: Some("me"),
603 names: &names,
604 };
605 let clock = CallClock {
606 offset: FixedOffset::east_opt(0).unwrap(),
607 today: NaiveDate::from_ymd_opt(2026, 10, 30).unwrap(),
608 meeting,
609 };
610 events
611 .iter()
612 .zip(records)
613 .enumerate()
614 .filter(|(index, _)| !timeline.hides(*index))
615 .map(|(_, (event, record))| {
616 call_card(
617 CallSource {
618 event: event.as_ref().unwrap(),
619 message_id: &record.message_id,
620 created_at: record.created_at,
621 time: "16:15",
622 },
623 &lookup,
624 &clock,
625 &timeline,
626 )
627 })
628 .collect()
629 }
630
631 fn notice_line(card: &CallCard) -> String {
632 let notice = &card.notice;
633 match &notice.emphasis {
634 Some(emphasis) => format!("{} {emphasis}", notice.text),
635 None => notice.text.clone(),
636 }
637 }
638
639 #[test]
640 fn recorded_meeting_shows_as_teams_notices() {
641 let shown = cards(&fixture_records(), &MeetingInfo::default());
642 let lines: Vec<String> = shown.iter().map(notice_line).collect();
643 assert_eq!(
644 lines,
645 [
646 "Meeting started",
647 "Sam Recorder started recording.",
648 "Recording stopped.",
649 "Meeting ended: 16m 28s",
650 "Recording has been saved to Vera Organizer's OneDrive.",
651 ]
652 );
653 let icons: Vec<CallIcon> = shown.iter().map(|card| card.icon).collect();
654 assert_eq!(
655 icons,
656 [
657 CallIcon::Video,
658 CallIcon::Record,
659 CallIcon::RecordStop,
660 CallIcon::Video,
661 CallIcon::Saved,
662 ]
663 );
664 assert!(
665 shown
666 .iter()
667 .all(|card| card.recap.is_none() == (card.title != "Meeting ended"))
668 );
669 }
670
671 #[test]
672 fn a_recording_stopped_before_the_end_names_who_stopped_it() {
673 let mut records = fixture_records();
674 for record in records.iter_mut() {
675 if teams_core::call_event(record)
676 .is_some_and(|event| event.phase == CallPhase::RecordingStopped)
677 {
678 record.created_at -= chrono::Duration::minutes(2);
679 }
680 }
681 let shown = cards(&records, &MeetingInfo::default());
682 assert_eq!(notice_line(&shown[2]), "Sam Recorder stopped recording.");
683 }
684
685 #[test]
686 fn ended_meeting_carries_the_recap_card_of_its_recording() {
687 let records = fixture_records();
688 let saved_id = records.last().unwrap().message_id.clone();
689 let meeting = MeetingInfo {
690 title: Some("Weekly sync".to_owned()),
691 slots: Vec::new(),
692 expiry_days: HashMap::from([(saved_id.clone(), 56)]),
693 };
694 let shown = cards(&records, &meeting);
695 let ended = shown
696 .iter()
697 .find(|card| card.title == "Meeting ended")
698 .unwrap();
699 let recap = ended.recap.as_ref().unwrap();
700 assert_eq!(recap.title, "Weekly sync");
701 assert_eq!(recap.recording.message_id, saved_id);
702 assert_eq!(recap.recording.duration.as_deref(), Some("13m 34s"));
703 assert_eq!(recap.recording.expires_in_days, Some(56));
704 assert!(recap.recording.transcript);
705 assert!(
706 recap
707 .recording
708 .thumbnail
709 .as_ref()
710 .unwrap()
711 .url
712 .contains("/thumbnails/")
713 );
714 assert!(shown.iter().filter(|card| card.recap.is_some()).count() == 1);
715 assert_eq!(
716 notice_line(shown.last().unwrap()),
717 "Recording has been saved to Vera Organizer's OneDrive and will expire in 56 days."
718 );
719 }
720
721 #[test]
722 fn recap_date_prefers_the_calendar_occurrence() {
723 let started_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 46, 0).unwrap();
724 let ended_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 55, 0).unwrap();
725 let mut meeting = MeetingInfo::default();
726 let clock = |meeting: &MeetingInfo| {
727 recap_date_line(
728 started_at,
729 ended_at,
730 &CallClock {
731 offset: FixedOffset::east_opt(2 * 3600).unwrap(),
732 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
733 meeting,
734 },
735 )
736 };
737 assert_eq!(clock(&meeting), "Thursday, 15 October 2026 11:46 - 11:55");
738 meeting.slots = vec![
739 MeetingSlot {
740 start: Utc.with_ymd_and_hms(2026, 10, 14, 9, 45, 0).unwrap(),
741 end: Utc.with_ymd_and_hms(2026, 10, 14, 10, 0, 0).unwrap(),
742 },
743 MeetingSlot {
744 start: Utc.with_ymd_and_hms(2026, 10, 15, 9, 45, 0).unwrap(),
745 end: Utc.with_ymd_and_hms(2026, 10, 15, 10, 0, 0).unwrap(),
746 },
747 ];
748 assert_eq!(clock(&meeting), "Thursday, 15 October 2026 11:45 - 12:00");
749 }
750
751 #[test]
752 fn notice_stamps_spell_out_the_weekday_like_teams() {
753 let meeting = MeetingInfo::default();
754 let clock = CallClock {
755 offset: FixedOffset::east_opt(0).unwrap(),
756 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
757 meeting: &meeting,
758 };
759 let stamp = |day: u32| {
760 notice_stamp(
761 Utc.with_ymd_and_hms(2026, 10, day, 11, 45, 0).unwrap(),
762 &clock,
763 )
764 };
765 assert_eq!(stamp(17), "11:45");
766 assert_eq!(stamp(16), "Yesterday 11:45");
767 assert_eq!(stamp(15), "Thursday 11:45");
768 }
769
770 #[test]
771 fn ended_meeting_lists_named_participants_up_to_four() {
772 let shown = cards(&fixture_records(), &MeetingInfo::default());
773 let ended = shown
774 .iter()
775 .find(|card| card.title == "Meeting ended")
776 .unwrap();
777 assert_eq!(ended.detail, "16m 28s \u{b7} 16:15");
778 let shown_names: Vec<&str> = ended
779 .participants
780 .iter()
781 .map(|person| person.name.as_str())
782 .collect();
783 assert_eq!(
784 shown_names,
785 ["Person 1", "Person 2", "Person 3", "Person 4"]
786 );
787 assert_eq!(ended.extra_participants, 20);
788 }
789
790 #[test]
791 fn meeting_start_stays_but_a_finished_call_start_hides() {
792 let events = vec![
793 Some(event(CallPhase::Started, CallType::Meeting, "meeting")),
794 Some(event(CallPhase::Ended, CallType::Meeting, "meeting")),
795 Some(event(CallPhase::Started, CallType::Call, "call")),
796 Some(event(CallPhase::Ended, CallType::Call, "call")),
797 Some(event(CallPhase::Started, CallType::Meeting, "live")),
798 None,
799 ];
800 let timeline = CallTimeline::new(&events);
801 assert!(!timeline.hides(0));
802 assert!(timeline.hides(2));
803 assert!(!timeline.hides(5));
804 assert!(timeline.is_live_start(4));
805 assert!(!timeline.is_live_start(0));
806 assert!(timeline.finished("meeting"));
807 }
808
809 #[test]
810 fn calls_read_like_teams_and_my_recording_is_in_my_onedrive() {
811 let names = HashMap::new();
812 let lookup = CallNames {
813 my_user_id: Some("me"),
814 names: &names,
815 };
816 let line = |event: &CallEvent, missed: bool| {
817 notice_text(
818 NoticeSource {
819 event,
820 message_id: "m",
821 missed,
822 stopped_by_meeting_end: false,
823 },
824 &lookup,
825 &MeetingInfo::default(),
826 )
827 };
828 let ended = event(CallPhase::Ended, CallType::Call, "c");
829 assert_eq!(line(&ended, false), "Call ended");
830 assert_eq!(line(&ended, true), "Call missed");
831 assert_eq!(
832 line(&event(CallPhase::Ended, CallType::Meeting, "c"), false),
833 "Meeting ended:"
834 );
835 let mut saved = event(CallPhase::RecordingSaved, CallType::Call, "c");
836 saved.recording = Some(Recording {
837 name: None,
838 url: Some("https://contoso.example/rec.mp4".to_owned()),
839 organizer_id: Some("me".to_owned()),
840 });
841 assert_eq!(
842 line(&saved, false),
843 "Recording has been saved to your OneDrive."
844 );
845 }
846}