BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-call-model / src / recording_menu.rs

recording_menu.rs

8629da58 History
recording_menu.rs 4.8 KiB Download Raw
1use calling::{RecordingKind, StopScope};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum RecordAction {
5 Start(RecordingKind),
6 Stop(StopScope),
7}
8
9impl RecordAction {
10 pub fn label(self) -> &'static str {
11 match self {
12 RecordAction::Start(RecordingKind::Video) => "Start recording",
13 RecordAction::Start(RecordingKind::AudioOnly) => "Record audio only",
14 RecordAction::Start(RecordingKind::TranscriptOnly) => "Start transcription only",
15 RecordAction::Stop(StopScope::Both | StopScope::RecordingOnly) => "Stop recording",
16 RecordAction::Stop(StopScope::TranscriptionOnly) => "Stop transcription",
17 }
18 }
19
20 pub fn confirm_title(self) -> Option<&'static str> {
21 match self {
22 RecordAction::Start(_) => None,
23 RecordAction::Stop(StopScope::Both) => Some("Stop recording and transcription?"),
24 RecordAction::Stop(StopScope::RecordingOnly) => Some("Stop recording?"),
25 RecordAction::Stop(StopScope::TranscriptionOnly) => Some("Stop transcription?"),
26 }
27 }
28}
29
30pub fn record_actions(recording: bool, transcribing: bool) -> Vec<(RecordAction, &'static str)> {
31 let labelled = |action: RecordAction| (action, action.label());
32 match (recording, transcribing) {
33 (false, false) => vec![
34 labelled(RecordAction::Start(RecordingKind::Video)),
35 labelled(RecordAction::Start(RecordingKind::AudioOnly)),
36 labelled(RecordAction::Start(RecordingKind::TranscriptOnly)),
37 ],
38 (true, true) => vec![
39 labelled(RecordAction::Stop(StopScope::RecordingOnly)),
40 labelled(RecordAction::Stop(StopScope::TranscriptionOnly)),
41 (RecordAction::Stop(StopScope::Both), "Stop both"),
42 ],
43 (true, false) => vec![labelled(RecordAction::Stop(StopScope::Both))],
44 (false, true) => vec![labelled(RecordAction::Stop(StopScope::TranscriptionOnly))],
45 }
46}
47
48#[derive(Debug, Clone, Copy, PartialEq, Eq)]
49pub enum RecordingChip {
50 Recording,
51 RecordingAudio,
52 Transcribing,
53}
54
55impl RecordingChip {
56 pub fn label(self) -> &'static str {
57 match self {
58 RecordingChip::Recording => "Recording",
59 RecordingChip::RecordingAudio => "Recording audio",
60 RecordingChip::Transcribing => "Transcribing",
61 }
62 }
63}
64
65pub fn recording_chip(recording: bool, audio_only: bool, transcribing: bool) -> Option<RecordingChip> {
66 match (recording, audio_only, transcribing) {
67 (true, true, _) => Some(RecordingChip::RecordingAudio),
68 (true, false, _) => Some(RecordingChip::Recording),
69 (false, _, true) => Some(RecordingChip::Transcribing),
70 (false, _, false) => None,
71 }
72}
73
74#[cfg(test)]
75mod tests {
76 use super::*;
77
78 fn labels(recording: bool, transcribing: bool) -> Vec<&'static str> {
79 record_actions(recording, transcribing).into_iter().map(|(_, label)| label).collect()
80 }
81
82 #[test]
83 fn nothing_running_offers_the_three_starts() {
84 assert_eq!(labels(false, false), ["Start recording", "Record audio only", "Start transcription only"]);
85 }
86
87 #[test]
88 fn recording_with_transcript_offers_the_three_stop_variants() {
89 let actions = record_actions(true, true);
90 assert_eq!(actions[0].0, RecordAction::Stop(StopScope::RecordingOnly));
91 assert_eq!(actions[1].0, RecordAction::Stop(StopScope::TranscriptionOnly));
92 assert_eq!(actions[2].0, RecordAction::Stop(StopScope::Both));
93 assert_eq!(labels(true, true), ["Stop recording", "Stop transcription", "Stop both"]);
94 }
95
96 #[test]
97 fn a_single_running_part_offers_the_one_matching_stop() {
98 assert_eq!(record_actions(true, false), [(RecordAction::Stop(StopScope::Both), "Stop recording")]);
99 assert_eq!(record_actions(false, true), [(RecordAction::Stop(StopScope::TranscriptionOnly), "Stop transcription")]);
100 }
101
102 #[test]
103 fn only_stops_ask_for_confirmation() {
104 assert_eq!(RecordAction::Start(RecordingKind::Video).confirm_title(), None);
105 assert_eq!(RecordAction::Stop(StopScope::Both).confirm_title(), Some("Stop recording and transcription?"));
106 assert_eq!(RecordAction::Stop(StopScope::RecordingOnly).confirm_title(), Some("Stop recording?"));
107 assert_eq!(RecordAction::Stop(StopScope::TranscriptionOnly).confirm_title(), Some("Stop transcription?"));
108 }
109
110 #[test]
111 fn the_chip_names_what_is_running() {
112 assert_eq!(recording_chip(true, false, true), Some(RecordingChip::Recording));
113 assert_eq!(recording_chip(true, true, true), Some(RecordingChip::RecordingAudio));
114 assert_eq!(recording_chip(false, false, true), Some(RecordingChip::Transcribing));
115 assert_eq!(recording_chip(false, false, false), None);
116 assert_eq!(RecordingChip::RecordingAudio.label(), "Recording audio");
117 }
118}