Skip to main content

sova_notifications/
channel.rs

1//! Named notification channels with optional ACL.
2
3/// Delivery channel config (code-defined, not a DB table).
4#[derive(Clone, Debug)]
5pub struct Channel {
6    pub slug: String,
7    /// Permission required to publish via HTTP broadcast (None = open to callers who hit the route guard).
8    pub publish: Option<String>,
9    /// Permission required to subscribe / list this channel (None = any authenticated recipient).
10    pub subscribe: Option<String>,
11}
12
13impl Channel {
14    pub fn new(slug: impl Into<String>) -> Self {
15        Self {
16            slug: slug.into(),
17            publish: None,
18            subscribe: None,
19        }
20    }
21
22    pub fn publish(mut self, permission: impl Into<String>) -> Self {
23        self.publish = Some(permission.into());
24        self
25    }
26
27    pub fn subscribe(mut self, permission: impl Into<String>) -> Self {
28        self.subscribe = Some(permission.into());
29        self
30    }
31}
32
33/// How a notification is delivered.
34#[derive(Clone, Copy, Debug, PartialEq, Eq)]
35pub enum Via {
36    Database,
37    #[cfg(feature = "ws")]
38    Ws,
39    #[cfg(feature = "mail")]
40    Mail,
41}