holochain_conductor_api/
signal_subscription.rs

1use holochain_serialized_bytes::prelude::*;
2use holochain_types::app::InstalledAppId;
3use holochain_zome_types::cell::CellId;
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7/// Declares updated Signal subscription settings for an App.
8/// This message is part of the AppInterfaceApi
9#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SerializedBytes)]
10pub struct SignalSubscription {
11    /// The app for which to manage subscription
12    installed_app_id: InstalledAppId,
13    /// Fine-grained per-cell filters
14    filters: SignalFilterSet,
15}
16
17/// Associate a SignalFilter with each Cell in an App.
18/// The filtering can be interpreted as inclusive or exclusive,
19/// depending on the use case.
20///
21/// An empty Exclude filter means "allow all signals" (subscribe to all).
22/// An empty Include filter means "block all signals" (unsubscribe from all).
23#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SerializedBytes)]
24pub enum SignalFilterSet {
25    /// Only allow signals from the specified Cells with the specified filters,
26    /// block everything else
27    Include(HashMap<CellId, SignalFilter>),
28    /// Only block signals from the specified Cells with the specified filters
29    /// allow everything else
30    Exclude(HashMap<CellId, SignalFilter>),
31}
32
33impl Default for SignalFilterSet {
34    fn default() -> Self {
35        // The default is no filter
36        Self::allow_all()
37    }
38}
39
40impl SignalFilterSet {
41    /// Allow all signals to come through (subscribe to all)
42    pub fn allow_all() -> Self {
43        SignalFilterSet::Exclude(HashMap::new())
44    }
45
46    /// Block all signals (unsubscribe from all)
47    pub fn block_all() -> Self {
48        SignalFilterSet::Include(HashMap::new())
49    }
50}
51
52/// Specifies fine-grained filter controls for the signals
53#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SerializedBytes)]
54pub struct SignalFilter;
55
56impl Default for SignalFilter {
57    fn default() -> Self {
58        // The default is no filter
59        Self::empty()
60    }
61}
62
63impl SignalFilter {
64    /// A passthrough filter which filters nothing
65    pub fn empty() -> Self {
66        SignalFilter
67    }
68}