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
use crate::types::*;
use crate::errors::*;
use uuid::Uuid;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Chat {
#[doc(hidden)]
#[serde(rename(serialize = "@type", deserialize = "@type"))]
td_name: String,
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
id: i64,
#[serde(rename(serialize = "type", deserialize = "type"))] type_: ChatType,
title: String,
photo: Option<ChatPhoto>,
permissions: ChatPermissions,
last_message: Option<Message>,
#[serde(deserialize_with = "serde_aux::field_attributes::deserialize_number_from_string")] order: isize,
is_pinned: bool,
is_marked_as_unread: bool,
is_sponsored: bool,
can_be_deleted_only_for_self: bool,
can_be_deleted_for_all_users: bool,
can_be_reported: bool,
default_disable_notification: bool,
unread_count: i64,
last_read_inbox_message_id: i64,
last_read_outbox_message_id: i64,
unread_mention_count: i64,
notification_settings: ChatNotificationSettings,
pinned_message_id: i64,
reply_markup_message_id: i64,
draft_message: Option<DraftMessage>,
client_data: String,
}
impl RObject for Chat {
#[doc(hidden)] fn td_name(&self) -> &'static str { "chat" }
#[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}
impl Chat {
pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
pub fn builder() -> RTDChatBuilder {
let mut inner = Chat::default();
inner.td_name = "chat".to_string();
inner.extra = Some(Uuid::new_v4().to_string());
RTDChatBuilder { inner }
}
pub fn id(&self) -> i64 { self.id }
pub fn type_(&self) -> &ChatType { &self.type_ }
pub fn title(&self) -> &String { &self.title }
pub fn photo(&self) -> &Option<ChatPhoto> { &self.photo }
pub fn permissions(&self) -> &ChatPermissions { &self.permissions }
pub fn last_message(&self) -> &Option<Message> { &self.last_message }
pub fn order(&self) -> isize { self.order }
pub fn is_pinned(&self) -> bool { self.is_pinned }
pub fn is_marked_as_unread(&self) -> bool { self.is_marked_as_unread }
pub fn is_sponsored(&self) -> bool { self.is_sponsored }
pub fn can_be_deleted_only_for_self(&self) -> bool { self.can_be_deleted_only_for_self }
pub fn can_be_deleted_for_all_users(&self) -> bool { self.can_be_deleted_for_all_users }
pub fn can_be_reported(&self) -> bool { self.can_be_reported }
pub fn default_disable_notification(&self) -> bool { self.default_disable_notification }
pub fn unread_count(&self) -> i64 { self.unread_count }
pub fn last_read_inbox_message_id(&self) -> i64 { self.last_read_inbox_message_id }
pub fn last_read_outbox_message_id(&self) -> i64 { self.last_read_outbox_message_id }
pub fn unread_mention_count(&self) -> i64 { self.unread_mention_count }
pub fn notification_settings(&self) -> &ChatNotificationSettings { &self.notification_settings }
pub fn pinned_message_id(&self) -> i64 { self.pinned_message_id }
pub fn reply_markup_message_id(&self) -> i64 { self.reply_markup_message_id }
pub fn draft_message(&self) -> &Option<DraftMessage> { &self.draft_message }
pub fn client_data(&self) -> &String { &self.client_data }
}
#[doc(hidden)]
pub struct RTDChatBuilder {
inner: Chat
}
impl RTDChatBuilder {
pub fn build(&self) -> Chat { self.inner.clone() }
pub fn id(&mut self, id: i64) -> &mut Self {
self.inner.id = id;
self
}
pub fn type_<T: AsRef<ChatType>>(&mut self, type_: T) -> &mut Self {
self.inner.type_ = type_.as_ref().clone();
self
}
pub fn title<T: AsRef<str>>(&mut self, title: T) -> &mut Self {
self.inner.title = title.as_ref().to_string();
self
}
pub fn photo<T: AsRef<ChatPhoto>>(&mut self, photo: T) -> &mut Self {
self.inner.photo = Some(photo.as_ref().clone());
self
}
pub fn permissions<T: AsRef<ChatPermissions>>(&mut self, permissions: T) -> &mut Self {
self.inner.permissions = permissions.as_ref().clone();
self
}
pub fn last_message<T: AsRef<Message>>(&mut self, last_message: T) -> &mut Self {
self.inner.last_message = Some(last_message.as_ref().clone());
self
}
pub fn order(&mut self, order: isize) -> &mut Self {
self.inner.order = order;
self
}
pub fn is_pinned(&mut self, is_pinned: bool) -> &mut Self {
self.inner.is_pinned = is_pinned;
self
}
pub fn is_marked_as_unread(&mut self, is_marked_as_unread: bool) -> &mut Self {
self.inner.is_marked_as_unread = is_marked_as_unread;
self
}
pub fn is_sponsored(&mut self, is_sponsored: bool) -> &mut Self {
self.inner.is_sponsored = is_sponsored;
self
}
pub fn can_be_deleted_only_for_self(&mut self, can_be_deleted_only_for_self: bool) -> &mut Self {
self.inner.can_be_deleted_only_for_self = can_be_deleted_only_for_self;
self
}
pub fn can_be_deleted_for_all_users(&mut self, can_be_deleted_for_all_users: bool) -> &mut Self {
self.inner.can_be_deleted_for_all_users = can_be_deleted_for_all_users;
self
}
pub fn can_be_reported(&mut self, can_be_reported: bool) -> &mut Self {
self.inner.can_be_reported = can_be_reported;
self
}
pub fn default_disable_notification(&mut self, default_disable_notification: bool) -> &mut Self {
self.inner.default_disable_notification = default_disable_notification;
self
}
pub fn unread_count(&mut self, unread_count: i64) -> &mut Self {
self.inner.unread_count = unread_count;
self
}
pub fn last_read_inbox_message_id(&mut self, last_read_inbox_message_id: i64) -> &mut Self {
self.inner.last_read_inbox_message_id = last_read_inbox_message_id;
self
}
pub fn last_read_outbox_message_id(&mut self, last_read_outbox_message_id: i64) -> &mut Self {
self.inner.last_read_outbox_message_id = last_read_outbox_message_id;
self
}
pub fn unread_mention_count(&mut self, unread_mention_count: i64) -> &mut Self {
self.inner.unread_mention_count = unread_mention_count;
self
}
pub fn notification_settings<T: AsRef<ChatNotificationSettings>>(&mut self, notification_settings: T) -> &mut Self {
self.inner.notification_settings = notification_settings.as_ref().clone();
self
}
pub fn pinned_message_id(&mut self, pinned_message_id: i64) -> &mut Self {
self.inner.pinned_message_id = pinned_message_id;
self
}
pub fn reply_markup_message_id(&mut self, reply_markup_message_id: i64) -> &mut Self {
self.inner.reply_markup_message_id = reply_markup_message_id;
self
}
pub fn draft_message<T: AsRef<DraftMessage>>(&mut self, draft_message: T) -> &mut Self {
self.inner.draft_message = Some(draft_message.as_ref().clone());
self
}
pub fn client_data<T: AsRef<str>>(&mut self, client_data: T) -> &mut Self {
self.inner.client_data = client_data.as_ref().to_string();
self
}
}
impl AsRef<Chat> for Chat {
fn as_ref(&self) -> &Chat { self }
}
impl AsRef<Chat> for RTDChatBuilder {
fn as_ref(&self) -> &Chat { &self.inner }
}