rtdlib/types/
supergroup.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Represents a supergroup or channel with zero or more members (subscribers in the case of channels). From the point of view of the system, a channel is a special kind of a supergroup: only administrators can post and see the list of members, and posts from all administrators use the name and photo of the channel instead of individual names and profile photos. Unlike supergroups, channels can have an unlimited number of subscribers
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct Supergroup {
12  #[doc(hidden)]
13  #[serde(rename(serialize = "@type", deserialize = "@type"))]
14  td_name: String,
15  #[doc(hidden)]
16  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
17  extra: Option<String>,
18  /// Supergroup or channel identifier
19  id: i64,
20  /// Username of the supergroup or channel; empty for private supergroups or channels
21  username: String,
22  /// Point in time (Unix timestamp) when the current user joined, or the point in time when the supergroup or channel was created, in case the user is not a member
23  date: i64,
24  /// Status of the current user in the supergroup or channel; custom title will be always empty
25  status: ChatMemberStatus,
26  /// Number of members in the supergroup or channel; 0 if unknown. Currently, it is guaranteed to be known only if the supergroup or channel was received through searchPublicChats, searchChatsNearby, getInactiveSupergroupChats, getSuitableDiscussionChats, getGroupsInCommon, or getUserPrivacySettingRules
27  member_count: i64,
28  /// True, if the channel has a discussion group, or the supergroup is the designated discussion group for a channel
29  has_linked_chat: bool,
30  /// True, if the supergroup is connected to a location, i.e. the supergroup is a location-based supergroup
31  has_location: bool,
32  /// True, if messages sent to the channel need to contain information about the sender. This field is only applicable to channels
33  sign_messages: bool,
34  /// True, if the slow mode is enabled in the supergroup
35  is_slow_mode_enabled: bool,
36  /// True, if the supergroup is a channel
37  is_channel: bool,
38  /// True, if the supergroup is a broadcast group, i.e. only administrators can send messages and there is no limit on the number of members
39  is_broadcast_group: bool,
40  /// True, if the supergroup or channel is verified
41  is_verified: bool,
42  /// If non-empty, contains a human-readable description of the reason why access to this supergroup or channel must be restricted
43  restriction_reason: String,
44  /// True, if many users reported this supergroup or channel as a scam
45  is_scam: bool,
46  /// True, if many users reported this supergroup or channel as a fake account
47  is_fake: bool,
48  
49}
50
51impl RObject for Supergroup {
52  #[doc(hidden)] fn td_name(&self) -> &'static str { "supergroup" }
53  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
54  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
55}
56
57
58
59impl Supergroup {
60  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
61  pub fn builder() -> RTDSupergroupBuilder {
62    let mut inner = Supergroup::default();
63    inner.td_name = "supergroup".to_string();
64    inner.extra = Some(Uuid::new_v4().to_string());
65    RTDSupergroupBuilder { inner }
66  }
67
68  pub fn id(&self) -> i64 { self.id }
69
70  pub fn username(&self) -> &String { &self.username }
71
72  pub fn date(&self) -> i64 { self.date }
73
74  pub fn status(&self) -> &ChatMemberStatus { &self.status }
75
76  pub fn member_count(&self) -> i64 { self.member_count }
77
78  pub fn has_linked_chat(&self) -> bool { self.has_linked_chat }
79
80  pub fn has_location(&self) -> bool { self.has_location }
81
82  pub fn sign_messages(&self) -> bool { self.sign_messages }
83
84  pub fn is_slow_mode_enabled(&self) -> bool { self.is_slow_mode_enabled }
85
86  pub fn is_channel(&self) -> bool { self.is_channel }
87
88  pub fn is_broadcast_group(&self) -> bool { self.is_broadcast_group }
89
90  pub fn is_verified(&self) -> bool { self.is_verified }
91
92  pub fn restriction_reason(&self) -> &String { &self.restriction_reason }
93
94  pub fn is_scam(&self) -> bool { self.is_scam }
95
96  pub fn is_fake(&self) -> bool { self.is_fake }
97
98}
99
100#[doc(hidden)]
101pub struct RTDSupergroupBuilder {
102  inner: Supergroup
103}
104
105impl RTDSupergroupBuilder {
106  pub fn build(&self) -> Supergroup { self.inner.clone() }
107
108   
109  pub fn id(&mut self, id: i64) -> &mut Self {
110    self.inner.id = id;
111    self
112  }
113
114   
115  pub fn username<T: AsRef<str>>(&mut self, username: T) -> &mut Self {
116    self.inner.username = username.as_ref().to_string();
117    self
118  }
119
120   
121  pub fn date(&mut self, date: i64) -> &mut Self {
122    self.inner.date = date;
123    self
124  }
125
126   
127  pub fn status<T: AsRef<ChatMemberStatus>>(&mut self, status: T) -> &mut Self {
128    self.inner.status = status.as_ref().clone();
129    self
130  }
131
132   
133  pub fn member_count(&mut self, member_count: i64) -> &mut Self {
134    self.inner.member_count = member_count;
135    self
136  }
137
138   
139  pub fn has_linked_chat(&mut self, has_linked_chat: bool) -> &mut Self {
140    self.inner.has_linked_chat = has_linked_chat;
141    self
142  }
143
144   
145  pub fn has_location(&mut self, has_location: bool) -> &mut Self {
146    self.inner.has_location = has_location;
147    self
148  }
149
150   
151  pub fn sign_messages(&mut self, sign_messages: bool) -> &mut Self {
152    self.inner.sign_messages = sign_messages;
153    self
154  }
155
156   
157  pub fn is_slow_mode_enabled(&mut self, is_slow_mode_enabled: bool) -> &mut Self {
158    self.inner.is_slow_mode_enabled = is_slow_mode_enabled;
159    self
160  }
161
162   
163  pub fn is_channel(&mut self, is_channel: bool) -> &mut Self {
164    self.inner.is_channel = is_channel;
165    self
166  }
167
168   
169  pub fn is_broadcast_group(&mut self, is_broadcast_group: bool) -> &mut Self {
170    self.inner.is_broadcast_group = is_broadcast_group;
171    self
172  }
173
174   
175  pub fn is_verified(&mut self, is_verified: bool) -> &mut Self {
176    self.inner.is_verified = is_verified;
177    self
178  }
179
180   
181  pub fn restriction_reason<T: AsRef<str>>(&mut self, restriction_reason: T) -> &mut Self {
182    self.inner.restriction_reason = restriction_reason.as_ref().to_string();
183    self
184  }
185
186   
187  pub fn is_scam(&mut self, is_scam: bool) -> &mut Self {
188    self.inner.is_scam = is_scam;
189    self
190  }
191
192   
193  pub fn is_fake(&mut self, is_fake: bool) -> &mut Self {
194    self.inner.is_fake = is_fake;
195    self
196  }
197
198}
199
200impl AsRef<Supergroup> for Supergroup {
201  fn as_ref(&self) -> &Supergroup { self }
202}
203
204impl AsRef<Supergroup> for RTDSupergroupBuilder {
205  fn as_ref(&self) -> &Supergroup { &self.inner }
206}
207
208
209