Skip to main content

sew_proto/recording/
apps.rs

1//! Recording in Apps: what started a recording, the rule a room records under, the level from
2//! which members of an App's Spaces may record, the org policy that requires recording, and the
3//! kinds of an App's recording feed.
4//!
5//! None of these values changes anything on an install that sets no recording setting: such an
6//! install's recordings are `manual` or `auto`, its rooms `none` or `auto`, and its Apps'
7//! start level `none`.
8
9use schemars::JsonSchema;
10use serde::{Deserialize, Serialize};
11
12coded_enum! {
13    /// What started a recording. Stored in `recordings.trigger`.
14    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
15    pub enum RecordingTrigger {
16        /// A person pressed Record (the start route).
17        Manual = "manual" => 1,
18        /// An auto-record room's first join.
19        Auto = "auto" => 2,
20        /// The room reached two people while recording is required.
21        Required = "required" => 3,
22    }
23}
24
25impl RecordingTrigger {
26    /// The trigger of a recording known only by its `auto` flag (rows written before
27    /// triggers existed): `auto` or `manual`.
28    pub const fn from_auto(auto: bool) -> RecordingTrigger {
29        if auto {
30            RecordingTrigger::Auto
31        } else {
32            RecordingTrigger::Manual
33        }
34    }
35
36    /// Whether the recording started without anyone pressing Record (`auto` or `required`).
37    pub const fn is_automatic(self) -> bool {
38        matches!(self, RecordingTrigger::Auto | RecordingTrigger::Required)
39    }
40}
41
42/// `manual`: what a payload without `trigger` reads as.
43impl Default for RecordingTrigger {
44    fn default() -> RecordingTrigger {
45        RecordingTrigger::Manual
46    }
47}
48
49/// `none`: what a payload without `recording_rule` reads as.
50impl Default for RecordingRule {
51    fn default() -> RecordingRule {
52        RecordingRule::None
53    }
54}
55
56impl RecordingRule {
57    /// Whether this is `none` (the field is then left out).
58    pub fn is_none(&self) -> bool {
59        *self == RecordingRule::None
60    }
61}
62
63unit_enum! {
64    /// The rule a voice room records under, as its settings and their sources resolve it.
65    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
66    pub enum RecordingRule {
67        /// People press Record.
68        None = "none",
69        /// The room records from its first join.
70        Auto = "auto",
71        /// The room records every call with two or more people.
72        Required = "required",
73    }
74}
75
76unit_enum! {
77    /// The lowest level of an App's governed Space whose members may start and stop
78    /// recordings. `member` means everyone in the Space. Stored as its wire string.
79    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
80    pub enum RecordingStartLevel {
81        /// Nobody through the App's levels (the default; roles and overwrites still apply).
82        None = "none",
83        /// Admins.
84        Admin = "admin",
85        /// Moderators and admins.
86        Moderator = "moderator",
87        /// Everyone in the Space.
88        Member = "member",
89    }
90}
91
92impl RecordingStartLevel {
93    /// The level used when nothing is set.
94    pub const DEFAULT: RecordingStartLevel = RecordingStartLevel::None;
95}
96
97unit_enum! {
98    /// Org policy `recording.required`: whether rooms record every call with two or more
99    /// people.
100    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
101    pub enum RecordingRequiredPolicy {
102        /// Not required by the org (the default; Apps, Spaces and channels may still require
103        /// it).
104        Off = "off",
105        /// Every call with two or more people is recorded.
106        MultiPerson = "multi_person",
107    }
108}
109
110coded_enum! {
111    /// What an event of an App's recording feed is. Stored in `recording_events.kind`.
112    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
113    pub enum RecordingEventKind {
114        /// A recording started.
115        Started = "started" => 1,
116        /// A recording stopped.
117        Stopped = "stopped" => 2,
118        /// Its transcript became final.
119        TranscriptReady = "transcript_ready" => 3,
120        /// Its audio expired.
121        AudioExpired = "audio_expired" => 4,
122        /// Its record message was deleted.
123        Deleted = "deleted" => 5,
124    }
125}
126
127#[cfg(test)]
128mod tests {
129    use super::*;
130
131    #[test]
132    fn codes_are_frozen() {
133        let t: Vec<(i16, &str)> = RecordingTrigger::ALL
134            .iter()
135            .map(|v| (v.as_i16(), v.as_str()))
136            .collect();
137        assert_eq!(t, [(1, "manual"), (2, "auto"), (3, "required")]);
138        let k: Vec<(i16, &str)> = RecordingEventKind::ALL
139            .iter()
140            .map(|v| (v.as_i16(), v.as_str()))
141            .collect();
142        assert_eq!(
143            k,
144            [
145                (1, "started"),
146                (2, "stopped"),
147                (3, "transcript_ready"),
148                (4, "audio_expired"),
149                (5, "deleted")
150            ]
151        );
152        assert_eq!(RecordingTrigger::from_i16(0), None);
153        assert_eq!(RecordingEventKind::from_i16(6), None);
154    }
155
156    #[test]
157    fn trigger_from_auto() {
158        assert_eq!(RecordingTrigger::from_auto(true), RecordingTrigger::Auto);
159        assert_eq!(RecordingTrigger::from_auto(false), RecordingTrigger::Manual);
160        assert!(RecordingTrigger::Required.is_automatic());
161        assert!(!RecordingTrigger::Manual.is_automatic());
162    }
163
164    #[test]
165    fn levels_and_policy_wire() {
166        let l: Vec<&str> = RecordingStartLevel::ALL
167            .iter()
168            .map(|v| v.as_str())
169            .collect();
170        assert_eq!(l, ["none", "admin", "moderator", "member"]);
171        assert_eq!(RecordingStartLevel::DEFAULT, RecordingStartLevel::None);
172        assert_eq!(
173            RecordingRequiredPolicy::from_wire("multi_person"),
174            Some(RecordingRequiredPolicy::MultiPerson)
175        );
176        let r: Vec<&str> = RecordingRule::ALL.iter().map(|v| v.as_str()).collect();
177        assert_eq!(r, ["none", "auto", "required"]);
178    }
179}