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 Message {
#[doc(hidden)]
#[serde(rename(serialize = "@type", deserialize = "@type"))]
td_name: String,
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
id: i64,
sender_user_id: i64,
chat_id: i64,
sending_state: Option<MessageSendingState>,
is_outgoing: bool,
can_be_edited: bool,
can_be_forwarded: bool,
can_be_deleted_only_for_self: bool,
can_be_deleted_for_all_users: bool,
is_channel_post: bool,
contains_unread_mention: bool,
date: i64,
edit_date: i64,
forward_info: Option<MessageForwardInfo>,
reply_to_message_id: i64,
ttl: i64,
ttl_expires_in: f32,
via_bot_user_id: i64,
author_signature: String,
views: i64,
#[serde(deserialize_with = "serde_aux::field_attributes::deserialize_number_from_string")] media_album_id: isize,
content: MessageContent,
reply_markup: Option<ReplyMarkup>,
}
impl RObject for Message {
#[doc(hidden)] fn td_name(&self) -> &'static str { "message" }
#[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}
impl Message {
pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
pub fn builder() -> RTDMessageBuilder {
let mut inner = Message::default();
inner.td_name = "message".to_string();
inner.extra = Some(Uuid::new_v4().to_string());
RTDMessageBuilder { inner }
}
pub fn id(&self) -> i64 { self.id }
pub fn sender_user_id(&self) -> i64 { self.sender_user_id }
pub fn chat_id(&self) -> i64 { self.chat_id }
pub fn sending_state(&self) -> &Option<MessageSendingState> { &self.sending_state }
pub fn is_outgoing(&self) -> bool { self.is_outgoing }
pub fn can_be_edited(&self) -> bool { self.can_be_edited }
pub fn can_be_forwarded(&self) -> bool { self.can_be_forwarded }
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 is_channel_post(&self) -> bool { self.is_channel_post }
pub fn contains_unread_mention(&self) -> bool { self.contains_unread_mention }
pub fn date(&self) -> i64 { self.date }
pub fn edit_date(&self) -> i64 { self.edit_date }
pub fn forward_info(&self) -> &Option<MessageForwardInfo> { &self.forward_info }
pub fn reply_to_message_id(&self) -> i64 { self.reply_to_message_id }
pub fn ttl(&self) -> i64 { self.ttl }
pub fn ttl_expires_in(&self) -> f32 { self.ttl_expires_in }
pub fn via_bot_user_id(&self) -> i64 { self.via_bot_user_id }
pub fn author_signature(&self) -> &String { &self.author_signature }
pub fn views(&self) -> i64 { self.views }
pub fn media_album_id(&self) -> isize { self.media_album_id }
pub fn content(&self) -> &MessageContent { &self.content }
pub fn reply_markup(&self) -> &Option<ReplyMarkup> { &self.reply_markup }
}
#[doc(hidden)]
pub struct RTDMessageBuilder {
inner: Message
}
impl RTDMessageBuilder {
pub fn build(&self) -> Message { self.inner.clone() }
pub fn id(&mut self, id: i64) -> &mut Self {
self.inner.id = id;
self
}
pub fn sender_user_id(&mut self, sender_user_id: i64) -> &mut Self {
self.inner.sender_user_id = sender_user_id;
self
}
pub fn chat_id(&mut self, chat_id: i64) -> &mut Self {
self.inner.chat_id = chat_id;
self
}
pub fn sending_state<T: AsRef<MessageSendingState>>(&mut self, sending_state: T) -> &mut Self {
self.inner.sending_state = Some(sending_state.as_ref().clone());
self
}
pub fn is_outgoing(&mut self, is_outgoing: bool) -> &mut Self {
self.inner.is_outgoing = is_outgoing;
self
}
pub fn can_be_edited(&mut self, can_be_edited: bool) -> &mut Self {
self.inner.can_be_edited = can_be_edited;
self
}
pub fn can_be_forwarded(&mut self, can_be_forwarded: bool) -> &mut Self {
self.inner.can_be_forwarded = can_be_forwarded;
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 is_channel_post(&mut self, is_channel_post: bool) -> &mut Self {
self.inner.is_channel_post = is_channel_post;
self
}
pub fn contains_unread_mention(&mut self, contains_unread_mention: bool) -> &mut Self {
self.inner.contains_unread_mention = contains_unread_mention;
self
}
pub fn date(&mut self, date: i64) -> &mut Self {
self.inner.date = date;
self
}
pub fn edit_date(&mut self, edit_date: i64) -> &mut Self {
self.inner.edit_date = edit_date;
self
}
pub fn forward_info<T: AsRef<MessageForwardInfo>>(&mut self, forward_info: T) -> &mut Self {
self.inner.forward_info = Some(forward_info.as_ref().clone());
self
}
pub fn reply_to_message_id(&mut self, reply_to_message_id: i64) -> &mut Self {
self.inner.reply_to_message_id = reply_to_message_id;
self
}
pub fn ttl(&mut self, ttl: i64) -> &mut Self {
self.inner.ttl = ttl;
self
}
pub fn ttl_expires_in(&mut self, ttl_expires_in: f32) -> &mut Self {
self.inner.ttl_expires_in = ttl_expires_in;
self
}
pub fn via_bot_user_id(&mut self, via_bot_user_id: i64) -> &mut Self {
self.inner.via_bot_user_id = via_bot_user_id;
self
}
pub fn author_signature<T: AsRef<str>>(&mut self, author_signature: T) -> &mut Self {
self.inner.author_signature = author_signature.as_ref().to_string();
self
}
pub fn views(&mut self, views: i64) -> &mut Self {
self.inner.views = views;
self
}
pub fn media_album_id(&mut self, media_album_id: isize) -> &mut Self {
self.inner.media_album_id = media_album_id;
self
}
pub fn content<T: AsRef<MessageContent>>(&mut self, content: T) -> &mut Self {
self.inner.content = content.as_ref().clone();
self
}
pub fn reply_markup<T: AsRef<ReplyMarkup>>(&mut self, reply_markup: T) -> &mut Self {
self.inner.reply_markup = Some(reply_markup.as_ref().clone());
self
}
}
impl AsRef<Message> for Message {
fn as_ref(&self) -> &Message { self }
}
impl AsRef<Message> for RTDMessageBuilder {
fn as_ref(&self) -> &Message { &self.inner }
}