rtdlib 1.8.70

TDLib for rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
use crate::errors::*;
use crate::types::*;
use uuid::Uuid;

use serde::de::{Deserialize, Deserializer};
use std::fmt::Debug;

/// TRAIT | Describes the last time the user was online
pub trait TDUserStatus: Debug + RObject {}

/// Describes the last time the user was online
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum UserStatus {
  #[doc(hidden)]
  _Default(()),
  /// The user's status has never been changed
  Empty(UserStatusEmpty),
  /// The user is offline, but was online last month
  LastMonth(UserStatusLastMonth),
  /// The user is offline, but was online last week
  LastWeek(UserStatusLastWeek),
  /// The user is offline
  Offline(UserStatusOffline),
  /// The user is online
  Online(UserStatusOnline),
  /// The user was online recently
  Recently(UserStatusRecently),
}

impl Default for UserStatus {
  fn default() -> Self {
    UserStatus::_Default(())
  }
}

impl<'de> Deserialize<'de> for UserStatus {
  fn deserialize<D>(deserializer: D) -> Result<UserStatus, D::Error>
  where
    D: Deserializer<'de>,
  {
    use serde::de::Error;
    rtd_enum_deserialize!(
      UserStatus,
      (userStatusEmpty, Empty);
      (userStatusLastMonth, LastMonth);
      (userStatusLastWeek, LastWeek);
      (userStatusOffline, Offline);
      (userStatusOnline, Online);
      (userStatusRecently, Recently);

    )(deserializer)
  }
}

impl RObject for UserStatus {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    match self {
      UserStatus::Empty(t) => t.td_name(),
      UserStatus::LastMonth(t) => t.td_name(),
      UserStatus::LastWeek(t) => t.td_name(),
      UserStatus::Offline(t) => t.td_name(),
      UserStatus::Online(t) => t.td_name(),
      UserStatus::Recently(t) => t.td_name(),

      _ => "-1",
    }
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    match self {
      UserStatus::Empty(t) => t.extra(),
      UserStatus::LastMonth(t) => t.extra(),
      UserStatus::LastWeek(t) => t.extra(),
      UserStatus::Offline(t) => t.extra(),
      UserStatus::Online(t) => t.extra(),
      UserStatus::Recently(t) => t.extra(),

      _ => None,
    }
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl UserStatus {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  #[doc(hidden)]
  pub fn _is_default(&self) -> bool {
    matches!(self, UserStatus::_Default(_))
  }

  pub fn is_empty(&self) -> bool {
    matches!(self, UserStatus::Empty(_))
  }
  pub fn is_last_month(&self) -> bool {
    matches!(self, UserStatus::LastMonth(_))
  }
  pub fn is_last_week(&self) -> bool {
    matches!(self, UserStatus::LastWeek(_))
  }
  pub fn is_offline(&self) -> bool {
    matches!(self, UserStatus::Offline(_))
  }
  pub fn is_online(&self) -> bool {
    matches!(self, UserStatus::Online(_))
  }
  pub fn is_recently(&self) -> bool {
    matches!(self, UserStatus::Recently(_))
  }

  pub fn on_empty<F: FnOnce(&UserStatusEmpty)>(&self, fnc: F) -> &Self {
    if let UserStatus::Empty(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_last_month<F: FnOnce(&UserStatusLastMonth)>(&self, fnc: F) -> &Self {
    if let UserStatus::LastMonth(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_last_week<F: FnOnce(&UserStatusLastWeek)>(&self, fnc: F) -> &Self {
    if let UserStatus::LastWeek(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_offline<F: FnOnce(&UserStatusOffline)>(&self, fnc: F) -> &Self {
    if let UserStatus::Offline(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_online<F: FnOnce(&UserStatusOnline)>(&self, fnc: F) -> &Self {
    if let UserStatus::Online(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_recently<F: FnOnce(&UserStatusRecently)>(&self, fnc: F) -> &Self {
    if let UserStatus::Recently(t) = self {
      fnc(t)
    };
    self
  }

  pub fn as_empty(&self) -> Option<&UserStatusEmpty> {
    if let UserStatus::Empty(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_last_month(&self) -> Option<&UserStatusLastMonth> {
    if let UserStatus::LastMonth(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_last_week(&self) -> Option<&UserStatusLastWeek> {
    if let UserStatus::LastWeek(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_offline(&self) -> Option<&UserStatusOffline> {
    if let UserStatus::Offline(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_online(&self) -> Option<&UserStatusOnline> {
    if let UserStatus::Online(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_recently(&self) -> Option<&UserStatusRecently> {
    if let UserStatus::Recently(t) = self {
      return Some(t);
    }
    None
  }

  pub fn empty<T: AsRef<UserStatusEmpty>>(t: T) -> Self {
    UserStatus::Empty(t.as_ref().clone())
  }

  pub fn last_month<T: AsRef<UserStatusLastMonth>>(t: T) -> Self {
    UserStatus::LastMonth(t.as_ref().clone())
  }

  pub fn last_week<T: AsRef<UserStatusLastWeek>>(t: T) -> Self {
    UserStatus::LastWeek(t.as_ref().clone())
  }

  pub fn offline<T: AsRef<UserStatusOffline>>(t: T) -> Self {
    UserStatus::Offline(t.as_ref().clone())
  }

  pub fn online<T: AsRef<UserStatusOnline>>(t: T) -> Self {
    UserStatus::Online(t.as_ref().clone())
  }

  pub fn recently<T: AsRef<UserStatusRecently>>(t: T) -> Self {
    UserStatus::Recently(t.as_ref().clone())
  }
}

impl AsRef<UserStatus> for UserStatus {
  fn as_ref(&self) -> &UserStatus {
    self
  }
}

/// The user's status has never been changed
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UserStatusEmpty {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
}

impl RObject for UserStatusEmpty {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "userStatusEmpty"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDUserStatus for UserStatusEmpty {}

impl UserStatusEmpty {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDUserStatusEmptyBuilder {
    let inner = UserStatusEmpty {
      td_name: "userStatusEmpty".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
    };
    RTDUserStatusEmptyBuilder { inner }
  }
}

#[doc(hidden)]
pub struct RTDUserStatusEmptyBuilder {
  inner: UserStatusEmpty,
}

impl RTDUserStatusEmptyBuilder {
  pub fn build(&self) -> UserStatusEmpty {
    self.inner.clone()
  }
}

impl AsRef<UserStatusEmpty> for UserStatusEmpty {
  fn as_ref(&self) -> &UserStatusEmpty {
    self
  }
}

impl AsRef<UserStatusEmpty> for RTDUserStatusEmptyBuilder {
  fn as_ref(&self) -> &UserStatusEmpty {
    &self.inner
  }
}

/// The user is offline, but was online last month
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UserStatusLastMonth {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Exact user's status is hidden because the current user enabled userPrivacySettingShowStatus privacy setting for the user and has no Telegram Premium
  by_my_privacy_settings: bool,
}

impl RObject for UserStatusLastMonth {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "userStatusLastMonth"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDUserStatus for UserStatusLastMonth {}

impl UserStatusLastMonth {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDUserStatusLastMonthBuilder {
    let inner = UserStatusLastMonth {
      td_name: "userStatusLastMonth".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDUserStatusLastMonthBuilder { inner }
  }

  pub fn by_my_privacy_settings(&self) -> bool {
    self.by_my_privacy_settings
  }
}

#[doc(hidden)]
pub struct RTDUserStatusLastMonthBuilder {
  inner: UserStatusLastMonth,
}

impl RTDUserStatusLastMonthBuilder {
  pub fn build(&self) -> UserStatusLastMonth {
    self.inner.clone()
  }

  pub fn by_my_privacy_settings(&mut self, by_my_privacy_settings: bool) -> &mut Self {
    self.inner.by_my_privacy_settings = by_my_privacy_settings;
    self
  }
}

impl AsRef<UserStatusLastMonth> for UserStatusLastMonth {
  fn as_ref(&self) -> &UserStatusLastMonth {
    self
  }
}

impl AsRef<UserStatusLastMonth> for RTDUserStatusLastMonthBuilder {
  fn as_ref(&self) -> &UserStatusLastMonth {
    &self.inner
  }
}

/// The user is offline, but was online last week
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UserStatusLastWeek {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Exact user's status is hidden because the current user enabled userPrivacySettingShowStatus privacy setting for the user and has no Telegram Premium
  by_my_privacy_settings: bool,
}

impl RObject for UserStatusLastWeek {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "userStatusLastWeek"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDUserStatus for UserStatusLastWeek {}

impl UserStatusLastWeek {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDUserStatusLastWeekBuilder {
    let inner = UserStatusLastWeek {
      td_name: "userStatusLastWeek".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDUserStatusLastWeekBuilder { inner }
  }

  pub fn by_my_privacy_settings(&self) -> bool {
    self.by_my_privacy_settings
  }
}

#[doc(hidden)]
pub struct RTDUserStatusLastWeekBuilder {
  inner: UserStatusLastWeek,
}

impl RTDUserStatusLastWeekBuilder {
  pub fn build(&self) -> UserStatusLastWeek {
    self.inner.clone()
  }

  pub fn by_my_privacy_settings(&mut self, by_my_privacy_settings: bool) -> &mut Self {
    self.inner.by_my_privacy_settings = by_my_privacy_settings;
    self
  }
}

impl AsRef<UserStatusLastWeek> for UserStatusLastWeek {
  fn as_ref(&self) -> &UserStatusLastWeek {
    self
  }
}

impl AsRef<UserStatusLastWeek> for RTDUserStatusLastWeekBuilder {
  fn as_ref(&self) -> &UserStatusLastWeek {
    &self.inner
  }
}

/// The user is offline
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UserStatusOffline {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Point in time (Unix timestamp) when the user was last online
  was_online: i64,
}

impl RObject for UserStatusOffline {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "userStatusOffline"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDUserStatus for UserStatusOffline {}

impl UserStatusOffline {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDUserStatusOfflineBuilder {
    let inner = UserStatusOffline {
      td_name: "userStatusOffline".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDUserStatusOfflineBuilder { inner }
  }

  pub fn was_online(&self) -> i64 {
    self.was_online
  }
}

#[doc(hidden)]
pub struct RTDUserStatusOfflineBuilder {
  inner: UserStatusOffline,
}

impl RTDUserStatusOfflineBuilder {
  pub fn build(&self) -> UserStatusOffline {
    self.inner.clone()
  }

  pub fn was_online(&mut self, was_online: i64) -> &mut Self {
    self.inner.was_online = was_online;
    self
  }
}

impl AsRef<UserStatusOffline> for UserStatusOffline {
  fn as_ref(&self) -> &UserStatusOffline {
    self
  }
}

impl AsRef<UserStatusOffline> for RTDUserStatusOfflineBuilder {
  fn as_ref(&self) -> &UserStatusOffline {
    &self.inner
  }
}

/// The user is online
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UserStatusOnline {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Point in time (Unix timestamp) when the user's online status will expire
  expires: i64,
}

impl RObject for UserStatusOnline {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "userStatusOnline"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDUserStatus for UserStatusOnline {}

impl UserStatusOnline {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDUserStatusOnlineBuilder {
    let inner = UserStatusOnline {
      td_name: "userStatusOnline".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDUserStatusOnlineBuilder { inner }
  }

  pub fn expires(&self) -> i64 {
    self.expires
  }
}

#[doc(hidden)]
pub struct RTDUserStatusOnlineBuilder {
  inner: UserStatusOnline,
}

impl RTDUserStatusOnlineBuilder {
  pub fn build(&self) -> UserStatusOnline {
    self.inner.clone()
  }

  pub fn expires(&mut self, expires: i64) -> &mut Self {
    self.inner.expires = expires;
    self
  }
}

impl AsRef<UserStatusOnline> for UserStatusOnline {
  fn as_ref(&self) -> &UserStatusOnline {
    self
  }
}

impl AsRef<UserStatusOnline> for RTDUserStatusOnlineBuilder {
  fn as_ref(&self) -> &UserStatusOnline {
    &self.inner
  }
}

/// The user was online recently
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UserStatusRecently {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Exact user's status is hidden because the current user enabled userPrivacySettingShowStatus privacy setting for the user and has no Telegram Premium
  by_my_privacy_settings: bool,
}

impl RObject for UserStatusRecently {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "userStatusRecently"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDUserStatus for UserStatusRecently {}

impl UserStatusRecently {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDUserStatusRecentlyBuilder {
    let inner = UserStatusRecently {
      td_name: "userStatusRecently".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDUserStatusRecentlyBuilder { inner }
  }

  pub fn by_my_privacy_settings(&self) -> bool {
    self.by_my_privacy_settings
  }
}

#[doc(hidden)]
pub struct RTDUserStatusRecentlyBuilder {
  inner: UserStatusRecently,
}

impl RTDUserStatusRecentlyBuilder {
  pub fn build(&self) -> UserStatusRecently {
    self.inner.clone()
  }

  pub fn by_my_privacy_settings(&mut self, by_my_privacy_settings: bool) -> &mut Self {
    self.inner.by_my_privacy_settings = by_my_privacy_settings;
    self
  }
}

impl AsRef<UserStatusRecently> for UserStatusRecently {
  fn as_ref(&self) -> &UserStatusRecently {
    self
  }
}

impl AsRef<UserStatusRecently> for RTDUserStatusRecentlyBuilder {
  fn as_ref(&self) -> &UserStatusRecently {
    &self.inner
  }
}