1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct Chat {
12 #[doc(hidden)]
13 #[serde(rename(serialize = "@type", deserialize = "@type"))]
14 td_name: String,
15 #[doc(hidden)]
16 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
17 extra: Option<String>,
18 id: i64,
20 #[serde(rename(serialize = "type", deserialize = "type"))] type_: ChatType,
22 title: String,
24 photo: Option<ChatPhotoInfo>,
26 permissions: ChatPermissions,
28 last_message: Option<Message>,
30 positions: Option<Vec<ChatPosition>>,
32 message_sender_id: Option<MessageSender>,
34 has_protected_content: bool,
36 is_marked_as_unread: bool,
38 is_blocked: bool,
40 has_scheduled_messages: bool,
42 can_be_deleted_only_for_self: bool,
44 can_be_deleted_for_all_users: bool,
46 can_be_reported: bool,
48 default_disable_notification: bool,
50 unread_count: i64,
52 last_read_inbox_message_id: i64,
54 last_read_outbox_message_id: i64,
56 unread_mention_count: i64,
58 notification_settings: ChatNotificationSettings,
60 message_ttl: i64,
62 theme_name: String,
64 action_bar: Option<ChatActionBar>,
66 video_chat: VideoChat,
68 pending_join_requests: Option<ChatJoinRequestsInfo>,
70 reply_markup_message_id: i64,
72 draft_message: Option<DraftMessage>,
74 client_data: String,
76
77}
78
79impl RObject for Chat {
80 #[doc(hidden)] fn td_name(&self) -> &'static str { "chat" }
81 #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
82 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
83}
84
85
86
87impl Chat {
88 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
89 pub fn builder() -> RTDChatBuilder {
90 let mut inner = Chat::default();
91 inner.td_name = "chat".to_string();
92 inner.extra = Some(Uuid::new_v4().to_string());
93 RTDChatBuilder { inner }
94 }
95
96 pub fn id(&self) -> i64 { self.id }
97
98 pub fn type_(&self) -> &ChatType { &self.type_ }
99
100 pub fn title(&self) -> &String { &self.title }
101
102 pub fn photo(&self) -> &Option<ChatPhotoInfo> { &self.photo }
103
104 pub fn permissions(&self) -> &ChatPermissions { &self.permissions }
105
106 pub fn last_message(&self) -> &Option<Message> { &self.last_message }
107
108 pub fn positions(&self) -> &Option<Vec<ChatPosition>> { &self.positions }
109
110 pub fn message_sender_id(&self) -> &Option<MessageSender> { &self.message_sender_id }
111
112 pub fn has_protected_content(&self) -> bool { self.has_protected_content }
113
114 pub fn is_marked_as_unread(&self) -> bool { self.is_marked_as_unread }
115
116 pub fn is_blocked(&self) -> bool { self.is_blocked }
117
118 pub fn has_scheduled_messages(&self) -> bool { self.has_scheduled_messages }
119
120 pub fn can_be_deleted_only_for_self(&self) -> bool { self.can_be_deleted_only_for_self }
121
122 pub fn can_be_deleted_for_all_users(&self) -> bool { self.can_be_deleted_for_all_users }
123
124 pub fn can_be_reported(&self) -> bool { self.can_be_reported }
125
126 pub fn default_disable_notification(&self) -> bool { self.default_disable_notification }
127
128 pub fn unread_count(&self) -> i64 { self.unread_count }
129
130 pub fn last_read_inbox_message_id(&self) -> i64 { self.last_read_inbox_message_id }
131
132 pub fn last_read_outbox_message_id(&self) -> i64 { self.last_read_outbox_message_id }
133
134 pub fn unread_mention_count(&self) -> i64 { self.unread_mention_count }
135
136 pub fn notification_settings(&self) -> &ChatNotificationSettings { &self.notification_settings }
137
138 pub fn message_ttl(&self) -> i64 { self.message_ttl }
139
140 pub fn theme_name(&self) -> &String { &self.theme_name }
141
142 pub fn action_bar(&self) -> &Option<ChatActionBar> { &self.action_bar }
143
144 pub fn video_chat(&self) -> &VideoChat { &self.video_chat }
145
146 pub fn pending_join_requests(&self) -> &Option<ChatJoinRequestsInfo> { &self.pending_join_requests }
147
148 pub fn reply_markup_message_id(&self) -> i64 { self.reply_markup_message_id }
149
150 pub fn draft_message(&self) -> &Option<DraftMessage> { &self.draft_message }
151
152 pub fn client_data(&self) -> &String { &self.client_data }
153
154}
155
156#[doc(hidden)]
157pub struct RTDChatBuilder {
158 inner: Chat
159}
160
161impl RTDChatBuilder {
162 pub fn build(&self) -> Chat { self.inner.clone() }
163
164
165 pub fn id(&mut self, id: i64) -> &mut Self {
166 self.inner.id = id;
167 self
168 }
169
170
171 pub fn type_<T: AsRef<ChatType>>(&mut self, type_: T) -> &mut Self {
172 self.inner.type_ = type_.as_ref().clone();
173 self
174 }
175
176
177 pub fn title<T: AsRef<str>>(&mut self, title: T) -> &mut Self {
178 self.inner.title = title.as_ref().to_string();
179 self
180 }
181
182
183 pub fn photo<T: AsRef<ChatPhotoInfo>>(&mut self, photo: T) -> &mut Self {
184 self.inner.photo = Some(photo.as_ref().clone());
185 self
186 }
187
188
189 pub fn permissions<T: AsRef<ChatPermissions>>(&mut self, permissions: T) -> &mut Self {
190 self.inner.permissions = permissions.as_ref().clone();
191 self
192 }
193
194
195 pub fn last_message<T: AsRef<Message>>(&mut self, last_message: T) -> &mut Self {
196 self.inner.last_message = Some(last_message.as_ref().clone());
197 self
198 }
199
200
201 pub fn positions(&mut self, positions: Vec<ChatPosition>) -> &mut Self {
202 self.inner.positions = Some(positions);
203 self
204 }
205
206
207 pub fn message_sender_id<T: AsRef<MessageSender>>(&mut self, message_sender_id: T) -> &mut Self {
208 self.inner.message_sender_id = Some(message_sender_id.as_ref().clone());
209 self
210 }
211
212
213 pub fn has_protected_content(&mut self, has_protected_content: bool) -> &mut Self {
214 self.inner.has_protected_content = has_protected_content;
215 self
216 }
217
218
219 pub fn is_marked_as_unread(&mut self, is_marked_as_unread: bool) -> &mut Self {
220 self.inner.is_marked_as_unread = is_marked_as_unread;
221 self
222 }
223
224
225 pub fn is_blocked(&mut self, is_blocked: bool) -> &mut Self {
226 self.inner.is_blocked = is_blocked;
227 self
228 }
229
230
231 pub fn has_scheduled_messages(&mut self, has_scheduled_messages: bool) -> &mut Self {
232 self.inner.has_scheduled_messages = has_scheduled_messages;
233 self
234 }
235
236
237 pub fn can_be_deleted_only_for_self(&mut self, can_be_deleted_only_for_self: bool) -> &mut Self {
238 self.inner.can_be_deleted_only_for_self = can_be_deleted_only_for_self;
239 self
240 }
241
242
243 pub fn can_be_deleted_for_all_users(&mut self, can_be_deleted_for_all_users: bool) -> &mut Self {
244 self.inner.can_be_deleted_for_all_users = can_be_deleted_for_all_users;
245 self
246 }
247
248
249 pub fn can_be_reported(&mut self, can_be_reported: bool) -> &mut Self {
250 self.inner.can_be_reported = can_be_reported;
251 self
252 }
253
254
255 pub fn default_disable_notification(&mut self, default_disable_notification: bool) -> &mut Self {
256 self.inner.default_disable_notification = default_disable_notification;
257 self
258 }
259
260
261 pub fn unread_count(&mut self, unread_count: i64) -> &mut Self {
262 self.inner.unread_count = unread_count;
263 self
264 }
265
266
267 pub fn last_read_inbox_message_id(&mut self, last_read_inbox_message_id: i64) -> &mut Self {
268 self.inner.last_read_inbox_message_id = last_read_inbox_message_id;
269 self
270 }
271
272
273 pub fn last_read_outbox_message_id(&mut self, last_read_outbox_message_id: i64) -> &mut Self {
274 self.inner.last_read_outbox_message_id = last_read_outbox_message_id;
275 self
276 }
277
278
279 pub fn unread_mention_count(&mut self, unread_mention_count: i64) -> &mut Self {
280 self.inner.unread_mention_count = unread_mention_count;
281 self
282 }
283
284
285 pub fn notification_settings<T: AsRef<ChatNotificationSettings>>(&mut self, notification_settings: T) -> &mut Self {
286 self.inner.notification_settings = notification_settings.as_ref().clone();
287 self
288 }
289
290
291 pub fn message_ttl(&mut self, message_ttl: i64) -> &mut Self {
292 self.inner.message_ttl = message_ttl;
293 self
294 }
295
296
297 pub fn theme_name<T: AsRef<str>>(&mut self, theme_name: T) -> &mut Self {
298 self.inner.theme_name = theme_name.as_ref().to_string();
299 self
300 }
301
302
303 pub fn action_bar<T: AsRef<ChatActionBar>>(&mut self, action_bar: T) -> &mut Self {
304 self.inner.action_bar = Some(action_bar.as_ref().clone());
305 self
306 }
307
308
309 pub fn video_chat<T: AsRef<VideoChat>>(&mut self, video_chat: T) -> &mut Self {
310 self.inner.video_chat = video_chat.as_ref().clone();
311 self
312 }
313
314
315 pub fn pending_join_requests<T: AsRef<ChatJoinRequestsInfo>>(&mut self, pending_join_requests: T) -> &mut Self {
316 self.inner.pending_join_requests = Some(pending_join_requests.as_ref().clone());
317 self
318 }
319
320
321 pub fn reply_markup_message_id(&mut self, reply_markup_message_id: i64) -> &mut Self {
322 self.inner.reply_markup_message_id = reply_markup_message_id;
323 self
324 }
325
326
327 pub fn draft_message<T: AsRef<DraftMessage>>(&mut self, draft_message: T) -> &mut Self {
328 self.inner.draft_message = Some(draft_message.as_ref().clone());
329 self
330 }
331
332
333 pub fn client_data<T: AsRef<str>>(&mut self, client_data: T) -> &mut Self {
334 self.inner.client_data = client_data.as_ref().to_string();
335 self
336 }
337
338}
339
340impl AsRef<Chat> for Chat {
341 fn as_ref(&self) -> &Chat { self }
342}
343
344impl AsRef<Chat> for RTDChatBuilder {
345 fn as_ref(&self) -> &Chat { &self.inner }
346}
347
348
349