rust_tdlib/types/
notification.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct Notification {
8 #[doc(hidden)]
9 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10 extra: Option<String>,
11 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12 client_id: Option<i32>,
13 #[serde(default)]
16 id: i32,
17 #[serde(default)]
20 date: i32,
21 #[serde(default)]
24 is_silent: bool,
25 #[serde(rename(serialize = "type", deserialize = "type"))]
28 #[serde(skip_serializing_if = "NotificationType::_is_default")]
29 type_: NotificationType,
30}
31
32impl RObject for Notification {
33 #[doc(hidden)]
34 fn extra(&self) -> Option<&str> {
35 self.extra.as_deref()
36 }
37 #[doc(hidden)]
38 fn client_id(&self) -> Option<i32> {
39 self.client_id
40 }
41}
42
43impl Notification {
44 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
45 Ok(serde_json::from_str(json.as_ref())?)
46 }
47 pub fn builder() -> NotificationBuilder {
48 let mut inner = Notification::default();
49 inner.extra = Some(Uuid::new_v4().to_string());
50
51 NotificationBuilder { inner }
52 }
53
54 pub fn id(&self) -> i32 {
55 self.id
56 }
57
58 pub fn date(&self) -> i32 {
59 self.date
60 }
61
62 pub fn is_silent(&self) -> bool {
63 self.is_silent
64 }
65
66 pub fn type_(&self) -> &NotificationType {
67 &self.type_
68 }
69}
70
71#[doc(hidden)]
72pub struct NotificationBuilder {
73 inner: Notification,
74}
75
76#[deprecated]
77pub type RTDNotificationBuilder = NotificationBuilder;
78
79impl NotificationBuilder {
80 pub fn build(&self) -> Notification {
81 self.inner.clone()
82 }
83
84 pub fn id(&mut self, id: i32) -> &mut Self {
85 self.inner.id = id;
86 self
87 }
88
89 pub fn date(&mut self, date: i32) -> &mut Self {
90 self.inner.date = date;
91 self
92 }
93
94 pub fn is_silent(&mut self, is_silent: bool) -> &mut Self {
95 self.inner.is_silent = is_silent;
96 self
97 }
98
99 pub fn type_<T: AsRef<NotificationType>>(&mut self, type_: T) -> &mut Self {
100 self.inner.type_ = type_.as_ref().clone();
101 self
102 }
103}
104
105impl AsRef<Notification> for Notification {
106 fn as_ref(&self) -> &Notification {
107 self
108 }
109}
110
111impl AsRef<Notification> for NotificationBuilder {
112 fn as_ref(&self) -> &Notification {
113 &self.inner
114 }
115}