rust_tdlib/types/
notification_group.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct NotificationGroup {
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(rename(serialize = "type", deserialize = "type"))]
20 #[serde(skip_serializing_if = "NotificationGroupType::_is_default")]
21 type_: NotificationGroupType,
22 #[serde(default)]
25 chat_id: i64,
26 #[serde(default)]
29 total_count: i32,
30 #[serde(default)]
33 notifications: Vec<Notification>,
34}
35
36impl RObject for NotificationGroup {
37 #[doc(hidden)]
38 fn extra(&self) -> Option<&str> {
39 self.extra.as_deref()
40 }
41 #[doc(hidden)]
42 fn client_id(&self) -> Option<i32> {
43 self.client_id
44 }
45}
46
47impl NotificationGroup {
48 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
49 Ok(serde_json::from_str(json.as_ref())?)
50 }
51 pub fn builder() -> NotificationGroupBuilder {
52 let mut inner = NotificationGroup::default();
53 inner.extra = Some(Uuid::new_v4().to_string());
54
55 NotificationGroupBuilder { inner }
56 }
57
58 pub fn id(&self) -> i32 {
59 self.id
60 }
61
62 pub fn type_(&self) -> &NotificationGroupType {
63 &self.type_
64 }
65
66 pub fn chat_id(&self) -> i64 {
67 self.chat_id
68 }
69
70 pub fn total_count(&self) -> i32 {
71 self.total_count
72 }
73
74 pub fn notifications(&self) -> &Vec<Notification> {
75 &self.notifications
76 }
77}
78
79#[doc(hidden)]
80pub struct NotificationGroupBuilder {
81 inner: NotificationGroup,
82}
83
84#[deprecated]
85pub type RTDNotificationGroupBuilder = NotificationGroupBuilder;
86
87impl NotificationGroupBuilder {
88 pub fn build(&self) -> NotificationGroup {
89 self.inner.clone()
90 }
91
92 pub fn id(&mut self, id: i32) -> &mut Self {
93 self.inner.id = id;
94 self
95 }
96
97 pub fn type_<T: AsRef<NotificationGroupType>>(&mut self, type_: T) -> &mut Self {
98 self.inner.type_ = type_.as_ref().clone();
99 self
100 }
101
102 pub fn chat_id(&mut self, chat_id: i64) -> &mut Self {
103 self.inner.chat_id = chat_id;
104 self
105 }
106
107 pub fn total_count(&mut self, total_count: i32) -> &mut Self {
108 self.inner.total_count = total_count;
109 self
110 }
111
112 pub fn notifications(&mut self, notifications: Vec<Notification>) -> &mut Self {
113 self.inner.notifications = notifications;
114 self
115 }
116}
117
118impl AsRef<NotificationGroup> for NotificationGroup {
119 fn as_ref(&self) -> &NotificationGroup {
120 self
121 }
122}
123
124impl AsRef<NotificationGroup> for NotificationGroupBuilder {
125 fn as_ref(&self) -> &NotificationGroup {
126 &self.inner
127 }
128}