rust_tdlib/types/
chat_type.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7pub trait TDChatType: Debug + RObject {}
9
10#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum ChatType {
14 #[doc(hidden)]
15 #[default]
16 _Default,
17 #[serde(rename = "chatTypeBasicGroup")]
19 BasicGroup(ChatTypeBasicGroup),
20 #[serde(rename = "chatTypePrivate")]
22 Private(ChatTypePrivate),
23 #[serde(rename = "chatTypeSecret")]
25 Secret(ChatTypeSecret),
26 #[serde(rename = "chatTypeSupergroup")]
28 Supergroup(ChatTypeSupergroup),
29}
30
31impl RObject for ChatType {
32 #[doc(hidden)]
33 fn extra(&self) -> Option<&str> {
34 match self {
35 ChatType::BasicGroup(t) => t.extra(),
36 ChatType::Private(t) => t.extra(),
37 ChatType::Secret(t) => t.extra(),
38 ChatType::Supergroup(t) => t.extra(),
39
40 _ => None,
41 }
42 }
43 #[doc(hidden)]
44 fn client_id(&self) -> Option<i32> {
45 match self {
46 ChatType::BasicGroup(t) => t.client_id(),
47 ChatType::Private(t) => t.client_id(),
48 ChatType::Secret(t) => t.client_id(),
49 ChatType::Supergroup(t) => t.client_id(),
50
51 _ => None,
52 }
53 }
54}
55
56impl ChatType {
57 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
58 Ok(serde_json::from_str(json.as_ref())?)
59 }
60 #[doc(hidden)]
61 pub fn _is_default(&self) -> bool {
62 matches!(self, ChatType::_Default)
63 }
64}
65
66impl AsRef<ChatType> for ChatType {
67 fn as_ref(&self) -> &ChatType {
68 self
69 }
70}
71
72#[derive(Debug, Clone, Default, Serialize, Deserialize)]
74pub struct ChatTypeBasicGroup {
75 #[doc(hidden)]
76 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
77 extra: Option<String>,
78 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
79 client_id: Option<i32>,
80 #[serde(default)]
83 basic_group_id: i64,
84}
85
86impl RObject for ChatTypeBasicGroup {
87 #[doc(hidden)]
88 fn extra(&self) -> Option<&str> {
89 self.extra.as_deref()
90 }
91 #[doc(hidden)]
92 fn client_id(&self) -> Option<i32> {
93 self.client_id
94 }
95}
96
97impl TDChatType for ChatTypeBasicGroup {}
98
99impl ChatTypeBasicGroup {
100 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
101 Ok(serde_json::from_str(json.as_ref())?)
102 }
103 pub fn builder() -> ChatTypeBasicGroupBuilder {
104 let mut inner = ChatTypeBasicGroup::default();
105 inner.extra = Some(Uuid::new_v4().to_string());
106
107 ChatTypeBasicGroupBuilder { inner }
108 }
109
110 pub fn basic_group_id(&self) -> i64 {
111 self.basic_group_id
112 }
113}
114
115#[doc(hidden)]
116pub struct ChatTypeBasicGroupBuilder {
117 inner: ChatTypeBasicGroup,
118}
119
120#[deprecated]
121pub type RTDChatTypeBasicGroupBuilder = ChatTypeBasicGroupBuilder;
122
123impl ChatTypeBasicGroupBuilder {
124 pub fn build(&self) -> ChatTypeBasicGroup {
125 self.inner.clone()
126 }
127
128 pub fn basic_group_id(&mut self, basic_group_id: i64) -> &mut Self {
129 self.inner.basic_group_id = basic_group_id;
130 self
131 }
132}
133
134impl AsRef<ChatTypeBasicGroup> for ChatTypeBasicGroup {
135 fn as_ref(&self) -> &ChatTypeBasicGroup {
136 self
137 }
138}
139
140impl AsRef<ChatTypeBasicGroup> for ChatTypeBasicGroupBuilder {
141 fn as_ref(&self) -> &ChatTypeBasicGroup {
142 &self.inner
143 }
144}
145
146#[derive(Debug, Clone, Default, Serialize, Deserialize)]
148pub struct ChatTypePrivate {
149 #[doc(hidden)]
150 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
151 extra: Option<String>,
152 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
153 client_id: Option<i32>,
154 #[serde(default)]
157 user_id: i64,
158}
159
160impl RObject for ChatTypePrivate {
161 #[doc(hidden)]
162 fn extra(&self) -> Option<&str> {
163 self.extra.as_deref()
164 }
165 #[doc(hidden)]
166 fn client_id(&self) -> Option<i32> {
167 self.client_id
168 }
169}
170
171impl TDChatType for ChatTypePrivate {}
172
173impl ChatTypePrivate {
174 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
175 Ok(serde_json::from_str(json.as_ref())?)
176 }
177 pub fn builder() -> ChatTypePrivateBuilder {
178 let mut inner = ChatTypePrivate::default();
179 inner.extra = Some(Uuid::new_v4().to_string());
180
181 ChatTypePrivateBuilder { inner }
182 }
183
184 pub fn user_id(&self) -> i64 {
185 self.user_id
186 }
187}
188
189#[doc(hidden)]
190pub struct ChatTypePrivateBuilder {
191 inner: ChatTypePrivate,
192}
193
194#[deprecated]
195pub type RTDChatTypePrivateBuilder = ChatTypePrivateBuilder;
196
197impl ChatTypePrivateBuilder {
198 pub fn build(&self) -> ChatTypePrivate {
199 self.inner.clone()
200 }
201
202 pub fn user_id(&mut self, user_id: i64) -> &mut Self {
203 self.inner.user_id = user_id;
204 self
205 }
206}
207
208impl AsRef<ChatTypePrivate> for ChatTypePrivate {
209 fn as_ref(&self) -> &ChatTypePrivate {
210 self
211 }
212}
213
214impl AsRef<ChatTypePrivate> for ChatTypePrivateBuilder {
215 fn as_ref(&self) -> &ChatTypePrivate {
216 &self.inner
217 }
218}
219
220#[derive(Debug, Clone, Default, Serialize, Deserialize)]
222pub struct ChatTypeSecret {
223 #[doc(hidden)]
224 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
225 extra: Option<String>,
226 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
227 client_id: Option<i32>,
228 #[serde(default)]
231 secret_chat_id: i32,
232 #[serde(default)]
235 user_id: i64,
236}
237
238impl RObject for ChatTypeSecret {
239 #[doc(hidden)]
240 fn extra(&self) -> Option<&str> {
241 self.extra.as_deref()
242 }
243 #[doc(hidden)]
244 fn client_id(&self) -> Option<i32> {
245 self.client_id
246 }
247}
248
249impl TDChatType for ChatTypeSecret {}
250
251impl ChatTypeSecret {
252 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
253 Ok(serde_json::from_str(json.as_ref())?)
254 }
255 pub fn builder() -> ChatTypeSecretBuilder {
256 let mut inner = ChatTypeSecret::default();
257 inner.extra = Some(Uuid::new_v4().to_string());
258
259 ChatTypeSecretBuilder { inner }
260 }
261
262 pub fn secret_chat_id(&self) -> i32 {
263 self.secret_chat_id
264 }
265
266 pub fn user_id(&self) -> i64 {
267 self.user_id
268 }
269}
270
271#[doc(hidden)]
272pub struct ChatTypeSecretBuilder {
273 inner: ChatTypeSecret,
274}
275
276#[deprecated]
277pub type RTDChatTypeSecretBuilder = ChatTypeSecretBuilder;
278
279impl ChatTypeSecretBuilder {
280 pub fn build(&self) -> ChatTypeSecret {
281 self.inner.clone()
282 }
283
284 pub fn secret_chat_id(&mut self, secret_chat_id: i32) -> &mut Self {
285 self.inner.secret_chat_id = secret_chat_id;
286 self
287 }
288
289 pub fn user_id(&mut self, user_id: i64) -> &mut Self {
290 self.inner.user_id = user_id;
291 self
292 }
293}
294
295impl AsRef<ChatTypeSecret> for ChatTypeSecret {
296 fn as_ref(&self) -> &ChatTypeSecret {
297 self
298 }
299}
300
301impl AsRef<ChatTypeSecret> for ChatTypeSecretBuilder {
302 fn as_ref(&self) -> &ChatTypeSecret {
303 &self.inner
304 }
305}
306
307#[derive(Debug, Clone, Default, Serialize, Deserialize)]
309pub struct ChatTypeSupergroup {
310 #[doc(hidden)]
311 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
312 extra: Option<String>,
313 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
314 client_id: Option<i32>,
315 #[serde(default)]
318 supergroup_id: i64,
319 #[serde(default)]
322 is_channel: bool,
323}
324
325impl RObject for ChatTypeSupergroup {
326 #[doc(hidden)]
327 fn extra(&self) -> Option<&str> {
328 self.extra.as_deref()
329 }
330 #[doc(hidden)]
331 fn client_id(&self) -> Option<i32> {
332 self.client_id
333 }
334}
335
336impl TDChatType for ChatTypeSupergroup {}
337
338impl ChatTypeSupergroup {
339 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
340 Ok(serde_json::from_str(json.as_ref())?)
341 }
342 pub fn builder() -> ChatTypeSupergroupBuilder {
343 let mut inner = ChatTypeSupergroup::default();
344 inner.extra = Some(Uuid::new_v4().to_string());
345
346 ChatTypeSupergroupBuilder { inner }
347 }
348
349 pub fn supergroup_id(&self) -> i64 {
350 self.supergroup_id
351 }
352
353 pub fn is_channel(&self) -> bool {
354 self.is_channel
355 }
356}
357
358#[doc(hidden)]
359pub struct ChatTypeSupergroupBuilder {
360 inner: ChatTypeSupergroup,
361}
362
363#[deprecated]
364pub type RTDChatTypeSupergroupBuilder = ChatTypeSupergroupBuilder;
365
366impl ChatTypeSupergroupBuilder {
367 pub fn build(&self) -> ChatTypeSupergroup {
368 self.inner.clone()
369 }
370
371 pub fn supergroup_id(&mut self, supergroup_id: i64) -> &mut Self {
372 self.inner.supergroup_id = supergroup_id;
373 self
374 }
375
376 pub fn is_channel(&mut self, is_channel: bool) -> &mut Self {
377 self.inner.is_channel = is_channel;
378 self
379 }
380}
381
382impl AsRef<ChatTypeSupergroup> for ChatTypeSupergroup {
383 fn as_ref(&self) -> &ChatTypeSupergroup {
384 self
385 }
386}
387
388impl AsRef<ChatTypeSupergroup> for ChatTypeSupergroupBuilder {
389 fn as_ref(&self) -> &ChatTypeSupergroup {
390 &self.inner
391 }
392}