BlueGit

ict rusty-teams

Files

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

recording_menu.rs

chore: cargo fmt the workspace
metis Daniel Däschle · pushed by metis · 2 weeks ago
a6592765 History
recording_menu.rs 5.4 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(
66 recording: bool,
67 audio_only: bool,
68 transcribing: bool,
69) -> Option<RecordingChip> {
70 match (recording, audio_only, transcribing) {
71 (true, true, _) => Some(RecordingChip::RecordingAudio),
72 (true, false, _) => Some(RecordingChip::Recording),
73 (false, _, true) => Some(RecordingChip::Transcribing),
74 (false, _, false) => None,
75 }
76}
77
78#[cfg(test)]
79mod tests {
80 use super::*;
81
82 fn labels(recording: bool, transcribing: bool) -> Vec<&'static str> {
83 record_actions(recording, transcribing)
84 .into_iter()
85 .map(|(_, label)| label)
86 .collect()
87 }
88
89 #[test]
90 fn nothing_running_offers_the_three_starts() {
91 assert_eq!(
92 labels(false, false),
93 [
94 "Start recording",
95 "Record audio only",
96 "Start transcription only"
97 ]
98 );
99 }
100
101 #[test]
102 fn recording_with_transcript_offers_the_three_stop_variants() {
103 let actions = record_actions(true, true);
104 assert_eq!(actions[0].0, RecordAction::Stop(StopScope::RecordingOnly));
105 assert_eq!(
106 actions[1].0,
107 RecordAction::Stop(StopScope::TranscriptionOnly)
108 );
109 assert_eq!(actions[2].0, RecordAction::Stop(StopScope::Both));
110 assert_eq!(
111 labels(true, true),
112 ["Stop recording", "Stop transcription", "Stop both"]
113 );
114 }
115
116 #[test]
117 fn a_single_running_part_offers_the_one_matching_stop() {
118 assert_eq!(
119 record_actions(true, false),
120 [(RecordAction::Stop(StopScope::Both), "Stop recording")]
121 );
122 assert_eq!(
123 record_actions(false, true),
124 [(
125 RecordAction::Stop(StopScope::TranscriptionOnly),
126 "Stop transcription"
127 )]
128 );
129 }
130
131 #[test]
132 fn only_stops_ask_for_confirmation() {
133 assert_eq!(
134 RecordAction::Start(RecordingKind::Video).confirm_title(),
135 None
136 );
137 assert_eq!(
138 RecordAction::Stop(StopScope::Both).confirm_title(),
139 Some("Stop recording and transcription?")
140 );
141 assert_eq!(
142 RecordAction::Stop(StopScope::RecordingOnly).confirm_title(),
143 Some("Stop recording?")
144 );
145 assert_eq!(
146 RecordAction::Stop(StopScope::TranscriptionOnly).confirm_title(),
147 Some("Stop transcription?")
148 );
149 }
150
151 #[test]
152 fn the_chip_names_what_is_running() {
153 assert_eq!(
154 recording_chip(true, false, true),
155 Some(RecordingChip::Recording)
156 );
157 assert_eq!(
158 recording_chip(true, true, true),
159 Some(RecordingChip::RecordingAudio)
160 );
161 assert_eq!(
162 recording_chip(false, false, true),
163 Some(RecordingChip::Transcribing)
164 );
165 assert_eq!(recording_chip(false, false, false), None);
166 assert_eq!(RecordingChip::RecordingAudio.label(), "Recording audio");
167 }
168}