summaryrefslogtreecommitdiffstats
path: root/src/entities/push.rs
blob: b277c8d40bb88c845ba618bd3865d1686ec5bfd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use serde::{Deserialize, Serialize};

/// Represents the `alerts` key of the `Subscription` object
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Default)]
pub struct Alerts {
    /// flag for follow alerts
    pub follow: Option<bool>,
    /// flag for favourite alerts
    pub favourite: Option<bool>,
    /// flag for reblog alerts
    pub reblog: Option<bool>,
    /// flag for mention alerts
    pub mention: Option<bool>,
}

/// Represents a new Push subscription
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct Subscription {
    /// The `id` of the subscription
    pub id: String,
    /// The endpoint of the subscription
    pub endpoint: String,
    /// The server key of the subscription
    pub server_key: String,
    /// The status of the alerts for this subscription
    pub alerts: Option<Alerts>,
}

pub(crate) mod add_subscription {
    use serde::Serialize;
    use super::Alerts;

    #[derive(Debug, Clone, PartialEq, Serialize, Default)]
    pub(crate) struct Form {
        pub(crate) subscription: Subscription,
        pub(crate) data: Option<Data>,
    }

    #[derive(Debug, Clone, PartialEq, Serialize, Default)]
    pub(crate) struct Subscription {
        pub(crate) endpoint: String,
        pub(crate) keys: Keys,
    }

    #[derive(Debug, Clone, PartialEq, Serialize, Default)]
    pub(crate) struct Keys {
        pub(crate) p256dh: String,
        pub(crate) auth: String,
    }

    #[derive(Debug, Clone, PartialEq, Serialize, Default)]
    pub(crate) struct Data {
        pub(crate) alerts: Option<Alerts>,
    }
}

pub(crate) mod update_data {
    use serde::Serialize;
    use super::Alerts;

    #[derive(Debug, Clone, PartialEq, Serialize, Default)]
    pub(crate) struct Data {
        pub(crate) alerts: Option<Alerts>,
    }

    #[derive(Debug, Clone, PartialEq, Serialize, Default)]
    pub(crate) struct Form {
        pub(crate) id: String,
        pub(crate) data: Data,
    }
}