1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7pub trait TDChatActionBar: Debug + RObject {}
9
10#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum ChatActionBar {
14 #[doc(hidden)]
15 #[default]
16 _Default,
17 #[serde(rename = "chatActionBarAddContact")]
19 AddContact(ChatActionBarAddContact),
20 #[serde(rename = "chatActionBarInviteMembers")]
22 InviteMembers(ChatActionBarInviteMembers),
23 #[serde(rename = "chatActionBarJoinRequest")]
25 JoinRequest(ChatActionBarJoinRequest),
26 #[serde(rename = "chatActionBarReportAddBlock")]
28 ReportAddBlock(ChatActionBarReportAddBlock),
29 #[serde(rename = "chatActionBarReportSpam")]
31 ReportSpam(ChatActionBarReportSpam),
32 #[serde(rename = "chatActionBarReportUnrelatedLocation")]
34 ReportUnrelatedLocation(ChatActionBarReportUnrelatedLocation),
35 #[serde(rename = "chatActionBarSharePhoneNumber")]
37 SharePhoneNumber(ChatActionBarSharePhoneNumber),
38}
39
40impl RObject for ChatActionBar {
41 #[doc(hidden)]
42 fn extra(&self) -> Option<&str> {
43 match self {
44 ChatActionBar::AddContact(t) => t.extra(),
45 ChatActionBar::InviteMembers(t) => t.extra(),
46 ChatActionBar::JoinRequest(t) => t.extra(),
47 ChatActionBar::ReportAddBlock(t) => t.extra(),
48 ChatActionBar::ReportSpam(t) => t.extra(),
49 ChatActionBar::ReportUnrelatedLocation(t) => t.extra(),
50 ChatActionBar::SharePhoneNumber(t) => t.extra(),
51
52 _ => None,
53 }
54 }
55 #[doc(hidden)]
56 fn client_id(&self) -> Option<i32> {
57 match self {
58 ChatActionBar::AddContact(t) => t.client_id(),
59 ChatActionBar::InviteMembers(t) => t.client_id(),
60 ChatActionBar::JoinRequest(t) => t.client_id(),
61 ChatActionBar::ReportAddBlock(t) => t.client_id(),
62 ChatActionBar::ReportSpam(t) => t.client_id(),
63 ChatActionBar::ReportUnrelatedLocation(t) => t.client_id(),
64 ChatActionBar::SharePhoneNumber(t) => t.client_id(),
65
66 _ => None,
67 }
68 }
69}
70
71impl ChatActionBar {
72 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
73 Ok(serde_json::from_str(json.as_ref())?)
74 }
75 #[doc(hidden)]
76 pub fn _is_default(&self) -> bool {
77 matches!(self, ChatActionBar::_Default)
78 }
79}
80
81impl AsRef<ChatActionBar> for ChatActionBar {
82 fn as_ref(&self) -> &ChatActionBar {
83 self
84 }
85}
86
87#[derive(Debug, Clone, Default, Serialize, Deserialize)]
89pub struct ChatActionBarAddContact {
90 #[doc(hidden)]
91 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
92 extra: Option<String>,
93 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
94 client_id: Option<i32>,
95}
96
97impl RObject for ChatActionBarAddContact {
98 #[doc(hidden)]
99 fn extra(&self) -> Option<&str> {
100 self.extra.as_deref()
101 }
102 #[doc(hidden)]
103 fn client_id(&self) -> Option<i32> {
104 self.client_id
105 }
106}
107
108impl TDChatActionBar for ChatActionBarAddContact {}
109
110impl ChatActionBarAddContact {
111 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
112 Ok(serde_json::from_str(json.as_ref())?)
113 }
114 pub fn builder() -> ChatActionBarAddContactBuilder {
115 let mut inner = ChatActionBarAddContact::default();
116 inner.extra = Some(Uuid::new_v4().to_string());
117
118 ChatActionBarAddContactBuilder { inner }
119 }
120}
121
122#[doc(hidden)]
123pub struct ChatActionBarAddContactBuilder {
124 inner: ChatActionBarAddContact,
125}
126
127#[deprecated]
128pub type RTDChatActionBarAddContactBuilder = ChatActionBarAddContactBuilder;
129
130impl ChatActionBarAddContactBuilder {
131 pub fn build(&self) -> ChatActionBarAddContact {
132 self.inner.clone()
133 }
134}
135
136impl AsRef<ChatActionBarAddContact> for ChatActionBarAddContact {
137 fn as_ref(&self) -> &ChatActionBarAddContact {
138 self
139 }
140}
141
142impl AsRef<ChatActionBarAddContact> for ChatActionBarAddContactBuilder {
143 fn as_ref(&self) -> &ChatActionBarAddContact {
144 &self.inner
145 }
146}
147
148#[derive(Debug, Clone, Default, Serialize, Deserialize)]
150pub struct ChatActionBarInviteMembers {
151 #[doc(hidden)]
152 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
153 extra: Option<String>,
154 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
155 client_id: Option<i32>,
156}
157
158impl RObject for ChatActionBarInviteMembers {
159 #[doc(hidden)]
160 fn extra(&self) -> Option<&str> {
161 self.extra.as_deref()
162 }
163 #[doc(hidden)]
164 fn client_id(&self) -> Option<i32> {
165 self.client_id
166 }
167}
168
169impl TDChatActionBar for ChatActionBarInviteMembers {}
170
171impl ChatActionBarInviteMembers {
172 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
173 Ok(serde_json::from_str(json.as_ref())?)
174 }
175 pub fn builder() -> ChatActionBarInviteMembersBuilder {
176 let mut inner = ChatActionBarInviteMembers::default();
177 inner.extra = Some(Uuid::new_v4().to_string());
178
179 ChatActionBarInviteMembersBuilder { inner }
180 }
181}
182
183#[doc(hidden)]
184pub struct ChatActionBarInviteMembersBuilder {
185 inner: ChatActionBarInviteMembers,
186}
187
188#[deprecated]
189pub type RTDChatActionBarInviteMembersBuilder = ChatActionBarInviteMembersBuilder;
190
191impl ChatActionBarInviteMembersBuilder {
192 pub fn build(&self) -> ChatActionBarInviteMembers {
193 self.inner.clone()
194 }
195}
196
197impl AsRef<ChatActionBarInviteMembers> for ChatActionBarInviteMembers {
198 fn as_ref(&self) -> &ChatActionBarInviteMembers {
199 self
200 }
201}
202
203impl AsRef<ChatActionBarInviteMembers> for ChatActionBarInviteMembersBuilder {
204 fn as_ref(&self) -> &ChatActionBarInviteMembers {
205 &self.inner
206 }
207}
208
209#[derive(Debug, Clone, Default, Serialize, Deserialize)]
211pub struct ChatActionBarJoinRequest {
212 #[doc(hidden)]
213 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
214 extra: Option<String>,
215 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
216 client_id: Option<i32>,
217 #[serde(default)]
220 title: String,
221 #[serde(default)]
224 is_channel: bool,
225 #[serde(default)]
228 request_date: i32,
229}
230
231impl RObject for ChatActionBarJoinRequest {
232 #[doc(hidden)]
233 fn extra(&self) -> Option<&str> {
234 self.extra.as_deref()
235 }
236 #[doc(hidden)]
237 fn client_id(&self) -> Option<i32> {
238 self.client_id
239 }
240}
241
242impl TDChatActionBar for ChatActionBarJoinRequest {}
243
244impl ChatActionBarJoinRequest {
245 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
246 Ok(serde_json::from_str(json.as_ref())?)
247 }
248 pub fn builder() -> ChatActionBarJoinRequestBuilder {
249 let mut inner = ChatActionBarJoinRequest::default();
250 inner.extra = Some(Uuid::new_v4().to_string());
251
252 ChatActionBarJoinRequestBuilder { inner }
253 }
254
255 pub fn title(&self) -> &String {
256 &self.title
257 }
258
259 pub fn is_channel(&self) -> bool {
260 self.is_channel
261 }
262
263 pub fn request_date(&self) -> i32 {
264 self.request_date
265 }
266}
267
268#[doc(hidden)]
269pub struct ChatActionBarJoinRequestBuilder {
270 inner: ChatActionBarJoinRequest,
271}
272
273#[deprecated]
274pub type RTDChatActionBarJoinRequestBuilder = ChatActionBarJoinRequestBuilder;
275
276impl ChatActionBarJoinRequestBuilder {
277 pub fn build(&self) -> ChatActionBarJoinRequest {
278 self.inner.clone()
279 }
280
281 pub fn title<T: AsRef<str>>(&mut self, title: T) -> &mut Self {
282 self.inner.title = title.as_ref().to_string();
283 self
284 }
285
286 pub fn is_channel(&mut self, is_channel: bool) -> &mut Self {
287 self.inner.is_channel = is_channel;
288 self
289 }
290
291 pub fn request_date(&mut self, request_date: i32) -> &mut Self {
292 self.inner.request_date = request_date;
293 self
294 }
295}
296
297impl AsRef<ChatActionBarJoinRequest> for ChatActionBarJoinRequest {
298 fn as_ref(&self) -> &ChatActionBarJoinRequest {
299 self
300 }
301}
302
303impl AsRef<ChatActionBarJoinRequest> for ChatActionBarJoinRequestBuilder {
304 fn as_ref(&self) -> &ChatActionBarJoinRequest {
305 &self.inner
306 }
307}
308
309#[derive(Debug, Clone, Default, Serialize, Deserialize)]
311pub struct ChatActionBarReportAddBlock {
312 #[doc(hidden)]
313 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
314 extra: Option<String>,
315 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
316 client_id: Option<i32>,
317 #[serde(default)]
320 can_unarchive: bool,
321 #[serde(default)]
324 distance: i32,
325}
326
327impl RObject for ChatActionBarReportAddBlock {
328 #[doc(hidden)]
329 fn extra(&self) -> Option<&str> {
330 self.extra.as_deref()
331 }
332 #[doc(hidden)]
333 fn client_id(&self) -> Option<i32> {
334 self.client_id
335 }
336}
337
338impl TDChatActionBar for ChatActionBarReportAddBlock {}
339
340impl ChatActionBarReportAddBlock {
341 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
342 Ok(serde_json::from_str(json.as_ref())?)
343 }
344 pub fn builder() -> ChatActionBarReportAddBlockBuilder {
345 let mut inner = ChatActionBarReportAddBlock::default();
346 inner.extra = Some(Uuid::new_v4().to_string());
347
348 ChatActionBarReportAddBlockBuilder { inner }
349 }
350
351 pub fn can_unarchive(&self) -> bool {
352 self.can_unarchive
353 }
354
355 pub fn distance(&self) -> i32 {
356 self.distance
357 }
358}
359
360#[doc(hidden)]
361pub struct ChatActionBarReportAddBlockBuilder {
362 inner: ChatActionBarReportAddBlock,
363}
364
365#[deprecated]
366pub type RTDChatActionBarReportAddBlockBuilder = ChatActionBarReportAddBlockBuilder;
367
368impl ChatActionBarReportAddBlockBuilder {
369 pub fn build(&self) -> ChatActionBarReportAddBlock {
370 self.inner.clone()
371 }
372
373 pub fn can_unarchive(&mut self, can_unarchive: bool) -> &mut Self {
374 self.inner.can_unarchive = can_unarchive;
375 self
376 }
377
378 pub fn distance(&mut self, distance: i32) -> &mut Self {
379 self.inner.distance = distance;
380 self
381 }
382}
383
384impl AsRef<ChatActionBarReportAddBlock> for ChatActionBarReportAddBlock {
385 fn as_ref(&self) -> &ChatActionBarReportAddBlock {
386 self
387 }
388}
389
390impl AsRef<ChatActionBarReportAddBlock> for ChatActionBarReportAddBlockBuilder {
391 fn as_ref(&self) -> &ChatActionBarReportAddBlock {
392 &self.inner
393 }
394}
395
396#[derive(Debug, Clone, Default, Serialize, Deserialize)]
398pub struct ChatActionBarReportSpam {
399 #[doc(hidden)]
400 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
401 extra: Option<String>,
402 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
403 client_id: Option<i32>,
404 #[serde(default)]
407 can_unarchive: bool,
408}
409
410impl RObject for ChatActionBarReportSpam {
411 #[doc(hidden)]
412 fn extra(&self) -> Option<&str> {
413 self.extra.as_deref()
414 }
415 #[doc(hidden)]
416 fn client_id(&self) -> Option<i32> {
417 self.client_id
418 }
419}
420
421impl TDChatActionBar for ChatActionBarReportSpam {}
422
423impl ChatActionBarReportSpam {
424 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
425 Ok(serde_json::from_str(json.as_ref())?)
426 }
427 pub fn builder() -> ChatActionBarReportSpamBuilder {
428 let mut inner = ChatActionBarReportSpam::default();
429 inner.extra = Some(Uuid::new_v4().to_string());
430
431 ChatActionBarReportSpamBuilder { inner }
432 }
433
434 pub fn can_unarchive(&self) -> bool {
435 self.can_unarchive
436 }
437}
438
439#[doc(hidden)]
440pub struct ChatActionBarReportSpamBuilder {
441 inner: ChatActionBarReportSpam,
442}
443
444#[deprecated]
445pub type RTDChatActionBarReportSpamBuilder = ChatActionBarReportSpamBuilder;
446
447impl ChatActionBarReportSpamBuilder {
448 pub fn build(&self) -> ChatActionBarReportSpam {
449 self.inner.clone()
450 }
451
452 pub fn can_unarchive(&mut self, can_unarchive: bool) -> &mut Self {
453 self.inner.can_unarchive = can_unarchive;
454 self
455 }
456}
457
458impl AsRef<ChatActionBarReportSpam> for ChatActionBarReportSpam {
459 fn as_ref(&self) -> &ChatActionBarReportSpam {
460 self
461 }
462}
463
464impl AsRef<ChatActionBarReportSpam> for ChatActionBarReportSpamBuilder {
465 fn as_ref(&self) -> &ChatActionBarReportSpam {
466 &self.inner
467 }
468}
469
470#[derive(Debug, Clone, Default, Serialize, Deserialize)]
472pub struct ChatActionBarReportUnrelatedLocation {
473 #[doc(hidden)]
474 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
475 extra: Option<String>,
476 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
477 client_id: Option<i32>,
478}
479
480impl RObject for ChatActionBarReportUnrelatedLocation {
481 #[doc(hidden)]
482 fn extra(&self) -> Option<&str> {
483 self.extra.as_deref()
484 }
485 #[doc(hidden)]
486 fn client_id(&self) -> Option<i32> {
487 self.client_id
488 }
489}
490
491impl TDChatActionBar for ChatActionBarReportUnrelatedLocation {}
492
493impl ChatActionBarReportUnrelatedLocation {
494 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
495 Ok(serde_json::from_str(json.as_ref())?)
496 }
497 pub fn builder() -> ChatActionBarReportUnrelatedLocationBuilder {
498 let mut inner = ChatActionBarReportUnrelatedLocation::default();
499 inner.extra = Some(Uuid::new_v4().to_string());
500
501 ChatActionBarReportUnrelatedLocationBuilder { inner }
502 }
503}
504
505#[doc(hidden)]
506pub struct ChatActionBarReportUnrelatedLocationBuilder {
507 inner: ChatActionBarReportUnrelatedLocation,
508}
509
510#[deprecated]
511pub type RTDChatActionBarReportUnrelatedLocationBuilder =
512 ChatActionBarReportUnrelatedLocationBuilder;
513
514impl ChatActionBarReportUnrelatedLocationBuilder {
515 pub fn build(&self) -> ChatActionBarReportUnrelatedLocation {
516 self.inner.clone()
517 }
518}
519
520impl AsRef<ChatActionBarReportUnrelatedLocation> for ChatActionBarReportUnrelatedLocation {
521 fn as_ref(&self) -> &ChatActionBarReportUnrelatedLocation {
522 self
523 }
524}
525
526impl AsRef<ChatActionBarReportUnrelatedLocation> for ChatActionBarReportUnrelatedLocationBuilder {
527 fn as_ref(&self) -> &ChatActionBarReportUnrelatedLocation {
528 &self.inner
529 }
530}
531
532#[derive(Debug, Clone, Default, Serialize, Deserialize)]
534pub struct ChatActionBarSharePhoneNumber {
535 #[doc(hidden)]
536 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
537 extra: Option<String>,
538 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
539 client_id: Option<i32>,
540}
541
542impl RObject for ChatActionBarSharePhoneNumber {
543 #[doc(hidden)]
544 fn extra(&self) -> Option<&str> {
545 self.extra.as_deref()
546 }
547 #[doc(hidden)]
548 fn client_id(&self) -> Option<i32> {
549 self.client_id
550 }
551}
552
553impl TDChatActionBar for ChatActionBarSharePhoneNumber {}
554
555impl ChatActionBarSharePhoneNumber {
556 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
557 Ok(serde_json::from_str(json.as_ref())?)
558 }
559 pub fn builder() -> ChatActionBarSharePhoneNumberBuilder {
560 let mut inner = ChatActionBarSharePhoneNumber::default();
561 inner.extra = Some(Uuid::new_v4().to_string());
562
563 ChatActionBarSharePhoneNumberBuilder { inner }
564 }
565}
566
567#[doc(hidden)]
568pub struct ChatActionBarSharePhoneNumberBuilder {
569 inner: ChatActionBarSharePhoneNumber,
570}
571
572#[deprecated]
573pub type RTDChatActionBarSharePhoneNumberBuilder = ChatActionBarSharePhoneNumberBuilder;
574
575impl ChatActionBarSharePhoneNumberBuilder {
576 pub fn build(&self) -> ChatActionBarSharePhoneNumber {
577 self.inner.clone()
578 }
579}
580
581impl AsRef<ChatActionBarSharePhoneNumber> for ChatActionBarSharePhoneNumber {
582 fn as_ref(&self) -> &ChatActionBarSharePhoneNumber {
583 self
584 }
585}
586
587impl AsRef<ChatActionBarSharePhoneNumber> for ChatActionBarSharePhoneNumberBuilder {
588 fn as_ref(&self) -> &ChatActionBarSharePhoneNumber {
589 &self.inner
590 }
591}