push_messaging/fcm/
notification.rs

1use builder_pattern::Builder;
2use serde::{Serialize, Deserialize};
3use serde_with::skip_serializing_none;
4
5#[skip_serializing_none]
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Builder)]
7pub struct Notification {
8    #[into]
9    #[default(None)]
10    pub badge: Option<String>,
11    #[into]
12    #[default(None)]
13    pub body: Option<String>,
14    #[into]
15    #[default(None)]
16    pub body_loc_args: Option<Vec<String>>,
17    #[into]
18    #[default(None)]
19    pub body_loc_key: Option<String>,
20    #[into]
21    #[default(None)]
22    pub click_action: Option<String>,
23    #[into]
24    #[default(None)]
25    pub color: Option<String>,
26    #[into]
27    #[default(None)]
28    pub icon: Option<String>,
29    #[into]
30    #[default(None)]
31    pub sound: Option<String>,
32    #[into]
33    #[default(None)]
34    pub tag: Option<String>,
35    #[into]
36    #[default(None)]
37    pub title: Option<String>,
38    #[into]
39    #[default(None)]
40    pub title_loc_args: Option<Vec<String>>,
41    #[into]
42    #[default(None)]
43    pub title_loc_key: Option<String>,
44}
45
46
47impl From<crate::client::notification::Notification> for Notification{
48    fn from(notification: crate::client::notification::Notification) -> Self {
49        Self {
50            badge: notification.badge,
51            body: notification.body,
52            body_loc_args: notification.body_loc_args,
53            body_loc_key: notification.body_loc_key,
54            click_action: Some(notification.click_action),
55            color: notification.color,
56            icon: notification.icon,
57            sound: notification.sound,
58            tag: notification.tag,
59            title: Some(notification.title),
60            title_loc_args: notification.title_loc_args,
61            title_loc_key: notification.title_loc_key,
62        }
63    }
64}
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_notification() {
72        let notification = Notification::new()
73            .badge("badge".to_string())
74            .body("body".to_string())
75            .body_loc_args(vec!["body_loc_args".to_string()])
76            .body_loc_key("body_loc_key".to_string())
77            .click_action("click_action".to_string())
78            .color("color".to_string())
79            .icon("icon".to_string())
80            .sound("sound".to_string())
81            .tag("tag".to_string())
82            .title("title".to_string())
83            .title_loc_args(vec!["title_loc_args".to_string()])
84            .title_loc_key("title_loc_key".to_string())
85            .build();
86
87        let expected = Notification {
88            badge: Some("badge".to_string()),
89            body: Some("body".to_string()),
90            body_loc_args: Some(vec!["body_loc_args".to_string()]),
91            body_loc_key: Some("body_loc_key".to_string()),
92            click_action: Some("click_action".to_string()),
93            color: Some("color".to_string()),
94            icon: Some("icon".to_string()),
95            sound: Some("sound".to_string()),
96            tag: Some("tag".to_string()),
97            title: Some("title".to_string()),
98            title_loc_args: Some(vec!["title_loc_args".to_string()]),
99            title_loc_key: Some("title_loc_key".to_string()),
100        };
101
102        assert_eq!(notification, expected);
103    }
104}