rust_tdlib/types/
chat_statistics.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7/// Contains a detailed statistics about a chat
8pub trait TDChatStatistics: Debug + RObject {}
9
10/// Contains a detailed statistics about a chat
11#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum ChatStatistics {
14    #[doc(hidden)]
15    #[default]
16    _Default,
17    /// A detailed statistics about a channel chat
18    #[serde(rename = "chatStatisticsChannel")]
19    Channel(ChatStatisticsChannel),
20    /// A detailed statistics about a supergroup chat
21    #[serde(rename = "chatStatisticsSupergroup")]
22    Supergroup(ChatStatisticsSupergroup),
23    /// Returns detailed statistics about a chat. Currently, this method can be used only for supergroups and channels. Can be used only if supergroupFullInfo.can_get_statistics == true
24    #[serde(rename = "getChatStatistics")]
25    GetChatStatistics(GetChatStatistics),
26}
27
28impl RObject for ChatStatistics {
29    #[doc(hidden)]
30    fn extra(&self) -> Option<&str> {
31        match self {
32            ChatStatistics::Channel(t) => t.extra(),
33            ChatStatistics::Supergroup(t) => t.extra(),
34            ChatStatistics::GetChatStatistics(t) => t.extra(),
35
36            _ => None,
37        }
38    }
39    #[doc(hidden)]
40    fn client_id(&self) -> Option<i32> {
41        match self {
42            ChatStatistics::Channel(t) => t.client_id(),
43            ChatStatistics::Supergroup(t) => t.client_id(),
44            ChatStatistics::GetChatStatistics(t) => t.client_id(),
45
46            _ => None,
47        }
48    }
49}
50
51impl ChatStatistics {
52    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
53        Ok(serde_json::from_str(json.as_ref())?)
54    }
55    #[doc(hidden)]
56    pub fn _is_default(&self) -> bool {
57        matches!(self, ChatStatistics::_Default)
58    }
59}
60
61impl AsRef<ChatStatistics> for ChatStatistics {
62    fn as_ref(&self) -> &ChatStatistics {
63        self
64    }
65}
66
67/// A detailed statistics about a channel chat
68#[derive(Debug, Clone, Default, Serialize, Deserialize)]
69pub struct ChatStatisticsChannel {
70    #[doc(hidden)]
71    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
72    extra: Option<String>,
73    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
74    client_id: Option<i32>,
75    /// A period to which the statistics applies
76    period: DateRange,
77    /// Number of members in the chat
78    member_count: StatisticalValue,
79    /// Mean number of times the recently sent messages was viewed
80    mean_view_count: StatisticalValue,
81    /// Mean number of times the recently sent messages was shared
82    mean_share_count: StatisticalValue,
83    /// A percentage of users with enabled notifications for the chat
84
85    #[serde(default)]
86    enabled_notifications_percentage: f32,
87    /// A graph containing number of members in the chat
88
89    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
90    member_count_graph: StatisticalGraph,
91    /// A graph containing number of members joined and left the chat
92
93    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
94    join_graph: StatisticalGraph,
95    /// A graph containing number of members muted and unmuted the chat
96
97    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
98    mute_graph: StatisticalGraph,
99    /// A graph containing number of message views in a given hour in the last two weeks
100
101    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
102    view_count_by_hour_graph: StatisticalGraph,
103    /// A graph containing number of message views per source
104
105    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
106    view_count_by_source_graph: StatisticalGraph,
107    /// A graph containing number of new member joins per source
108
109    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
110    join_by_source_graph: StatisticalGraph,
111    /// A graph containing number of users viewed chat messages per language
112
113    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
114    language_graph: StatisticalGraph,
115    /// A graph containing number of chat message views and shares
116
117    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
118    message_interaction_graph: StatisticalGraph,
119    /// A graph containing number of views of associated with the chat instant views
120
121    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
122    instant_view_interaction_graph: StatisticalGraph,
123    /// Detailed statistics about number of views and shares of recently sent messages
124
125    #[serde(default)]
126    recent_message_interactions: Vec<ChatStatisticsMessageInteractionInfo>,
127}
128
129impl RObject for ChatStatisticsChannel {
130    #[doc(hidden)]
131    fn extra(&self) -> Option<&str> {
132        self.extra.as_deref()
133    }
134    #[doc(hidden)]
135    fn client_id(&self) -> Option<i32> {
136        self.client_id
137    }
138}
139
140impl TDChatStatistics for ChatStatisticsChannel {}
141
142impl ChatStatisticsChannel {
143    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
144        Ok(serde_json::from_str(json.as_ref())?)
145    }
146    pub fn builder() -> ChatStatisticsChannelBuilder {
147        let mut inner = ChatStatisticsChannel::default();
148        inner.extra = Some(Uuid::new_v4().to_string());
149
150        ChatStatisticsChannelBuilder { inner }
151    }
152
153    pub fn period(&self) -> &DateRange {
154        &self.period
155    }
156
157    pub fn member_count(&self) -> &StatisticalValue {
158        &self.member_count
159    }
160
161    pub fn mean_view_count(&self) -> &StatisticalValue {
162        &self.mean_view_count
163    }
164
165    pub fn mean_share_count(&self) -> &StatisticalValue {
166        &self.mean_share_count
167    }
168
169    pub fn enabled_notifications_percentage(&self) -> f32 {
170        self.enabled_notifications_percentage
171    }
172
173    pub fn member_count_graph(&self) -> &StatisticalGraph {
174        &self.member_count_graph
175    }
176
177    pub fn join_graph(&self) -> &StatisticalGraph {
178        &self.join_graph
179    }
180
181    pub fn mute_graph(&self) -> &StatisticalGraph {
182        &self.mute_graph
183    }
184
185    pub fn view_count_by_hour_graph(&self) -> &StatisticalGraph {
186        &self.view_count_by_hour_graph
187    }
188
189    pub fn view_count_by_source_graph(&self) -> &StatisticalGraph {
190        &self.view_count_by_source_graph
191    }
192
193    pub fn join_by_source_graph(&self) -> &StatisticalGraph {
194        &self.join_by_source_graph
195    }
196
197    pub fn language_graph(&self) -> &StatisticalGraph {
198        &self.language_graph
199    }
200
201    pub fn message_interaction_graph(&self) -> &StatisticalGraph {
202        &self.message_interaction_graph
203    }
204
205    pub fn instant_view_interaction_graph(&self) -> &StatisticalGraph {
206        &self.instant_view_interaction_graph
207    }
208
209    pub fn recent_message_interactions(&self) -> &Vec<ChatStatisticsMessageInteractionInfo> {
210        &self.recent_message_interactions
211    }
212}
213
214#[doc(hidden)]
215pub struct ChatStatisticsChannelBuilder {
216    inner: ChatStatisticsChannel,
217}
218
219#[deprecated]
220pub type RTDChatStatisticsChannelBuilder = ChatStatisticsChannelBuilder;
221
222impl ChatStatisticsChannelBuilder {
223    pub fn build(&self) -> ChatStatisticsChannel {
224        self.inner.clone()
225    }
226
227    pub fn period<T: AsRef<DateRange>>(&mut self, period: T) -> &mut Self {
228        self.inner.period = period.as_ref().clone();
229        self
230    }
231
232    pub fn member_count<T: AsRef<StatisticalValue>>(&mut self, member_count: T) -> &mut Self {
233        self.inner.member_count = member_count.as_ref().clone();
234        self
235    }
236
237    pub fn mean_view_count<T: AsRef<StatisticalValue>>(&mut self, mean_view_count: T) -> &mut Self {
238        self.inner.mean_view_count = mean_view_count.as_ref().clone();
239        self
240    }
241
242    pub fn mean_share_count<T: AsRef<StatisticalValue>>(
243        &mut self,
244        mean_share_count: T,
245    ) -> &mut Self {
246        self.inner.mean_share_count = mean_share_count.as_ref().clone();
247        self
248    }
249
250    pub fn enabled_notifications_percentage(
251        &mut self,
252        enabled_notifications_percentage: f32,
253    ) -> &mut Self {
254        self.inner.enabled_notifications_percentage = enabled_notifications_percentage;
255        self
256    }
257
258    pub fn member_count_graph<T: AsRef<StatisticalGraph>>(
259        &mut self,
260        member_count_graph: T,
261    ) -> &mut Self {
262        self.inner.member_count_graph = member_count_graph.as_ref().clone();
263        self
264    }
265
266    pub fn join_graph<T: AsRef<StatisticalGraph>>(&mut self, join_graph: T) -> &mut Self {
267        self.inner.join_graph = join_graph.as_ref().clone();
268        self
269    }
270
271    pub fn mute_graph<T: AsRef<StatisticalGraph>>(&mut self, mute_graph: T) -> &mut Self {
272        self.inner.mute_graph = mute_graph.as_ref().clone();
273        self
274    }
275
276    pub fn view_count_by_hour_graph<T: AsRef<StatisticalGraph>>(
277        &mut self,
278        view_count_by_hour_graph: T,
279    ) -> &mut Self {
280        self.inner.view_count_by_hour_graph = view_count_by_hour_graph.as_ref().clone();
281        self
282    }
283
284    pub fn view_count_by_source_graph<T: AsRef<StatisticalGraph>>(
285        &mut self,
286        view_count_by_source_graph: T,
287    ) -> &mut Self {
288        self.inner.view_count_by_source_graph = view_count_by_source_graph.as_ref().clone();
289        self
290    }
291
292    pub fn join_by_source_graph<T: AsRef<StatisticalGraph>>(
293        &mut self,
294        join_by_source_graph: T,
295    ) -> &mut Self {
296        self.inner.join_by_source_graph = join_by_source_graph.as_ref().clone();
297        self
298    }
299
300    pub fn language_graph<T: AsRef<StatisticalGraph>>(&mut self, language_graph: T) -> &mut Self {
301        self.inner.language_graph = language_graph.as_ref().clone();
302        self
303    }
304
305    pub fn message_interaction_graph<T: AsRef<StatisticalGraph>>(
306        &mut self,
307        message_interaction_graph: T,
308    ) -> &mut Self {
309        self.inner.message_interaction_graph = message_interaction_graph.as_ref().clone();
310        self
311    }
312
313    pub fn instant_view_interaction_graph<T: AsRef<StatisticalGraph>>(
314        &mut self,
315        instant_view_interaction_graph: T,
316    ) -> &mut Self {
317        self.inner.instant_view_interaction_graph = instant_view_interaction_graph.as_ref().clone();
318        self
319    }
320
321    pub fn recent_message_interactions(
322        &mut self,
323        recent_message_interactions: Vec<ChatStatisticsMessageInteractionInfo>,
324    ) -> &mut Self {
325        self.inner.recent_message_interactions = recent_message_interactions;
326        self
327    }
328}
329
330impl AsRef<ChatStatisticsChannel> for ChatStatisticsChannel {
331    fn as_ref(&self) -> &ChatStatisticsChannel {
332        self
333    }
334}
335
336impl AsRef<ChatStatisticsChannel> for ChatStatisticsChannelBuilder {
337    fn as_ref(&self) -> &ChatStatisticsChannel {
338        &self.inner
339    }
340}
341
342/// A detailed statistics about a supergroup chat
343#[derive(Debug, Clone, Default, Serialize, Deserialize)]
344pub struct ChatStatisticsSupergroup {
345    #[doc(hidden)]
346    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
347    extra: Option<String>,
348    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
349    client_id: Option<i32>,
350    /// A period to which the statistics applies
351    period: DateRange,
352    /// Number of members in the chat
353    member_count: StatisticalValue,
354    /// Number of messages sent to the chat
355    message_count: StatisticalValue,
356    /// Number of users who viewed messages in the chat
357    viewer_count: StatisticalValue,
358    /// Number of users who sent messages to the chat
359    sender_count: StatisticalValue,
360    /// A graph containing number of members in the chat
361
362    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
363    member_count_graph: StatisticalGraph,
364    /// A graph containing number of members joined and left the chat
365
366    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
367    join_graph: StatisticalGraph,
368    /// A graph containing number of new member joins per source
369
370    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
371    join_by_source_graph: StatisticalGraph,
372    /// A graph containing distribution of active users per language
373
374    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
375    language_graph: StatisticalGraph,
376    /// A graph containing distribution of sent messages by content type
377
378    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
379    message_content_graph: StatisticalGraph,
380    /// A graph containing number of different actions in the chat
381
382    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
383    action_graph: StatisticalGraph,
384    /// A graph containing distribution of message views per hour
385
386    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
387    day_graph: StatisticalGraph,
388    /// A graph containing distribution of message views per day of week
389
390    #[serde(skip_serializing_if = "StatisticalGraph::_is_default")]
391    week_graph: StatisticalGraph,
392    /// List of users sent most messages in the last week
393
394    #[serde(default)]
395    top_senders: Vec<ChatStatisticsMessageSenderInfo>,
396    /// List of most active administrators in the last week
397
398    #[serde(default)]
399    top_administrators: Vec<ChatStatisticsAdministratorActionsInfo>,
400    /// List of most active inviters of new members in the last week
401
402    #[serde(default)]
403    top_inviters: Vec<ChatStatisticsInviterInfo>,
404}
405
406impl RObject for ChatStatisticsSupergroup {
407    #[doc(hidden)]
408    fn extra(&self) -> Option<&str> {
409        self.extra.as_deref()
410    }
411    #[doc(hidden)]
412    fn client_id(&self) -> Option<i32> {
413        self.client_id
414    }
415}
416
417impl TDChatStatistics for ChatStatisticsSupergroup {}
418
419impl ChatStatisticsSupergroup {
420    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
421        Ok(serde_json::from_str(json.as_ref())?)
422    }
423    pub fn builder() -> ChatStatisticsSupergroupBuilder {
424        let mut inner = ChatStatisticsSupergroup::default();
425        inner.extra = Some(Uuid::new_v4().to_string());
426
427        ChatStatisticsSupergroupBuilder { inner }
428    }
429
430    pub fn period(&self) -> &DateRange {
431        &self.period
432    }
433
434    pub fn member_count(&self) -> &StatisticalValue {
435        &self.member_count
436    }
437
438    pub fn message_count(&self) -> &StatisticalValue {
439        &self.message_count
440    }
441
442    pub fn viewer_count(&self) -> &StatisticalValue {
443        &self.viewer_count
444    }
445
446    pub fn sender_count(&self) -> &StatisticalValue {
447        &self.sender_count
448    }
449
450    pub fn member_count_graph(&self) -> &StatisticalGraph {
451        &self.member_count_graph
452    }
453
454    pub fn join_graph(&self) -> &StatisticalGraph {
455        &self.join_graph
456    }
457
458    pub fn join_by_source_graph(&self) -> &StatisticalGraph {
459        &self.join_by_source_graph
460    }
461
462    pub fn language_graph(&self) -> &StatisticalGraph {
463        &self.language_graph
464    }
465
466    pub fn message_content_graph(&self) -> &StatisticalGraph {
467        &self.message_content_graph
468    }
469
470    pub fn action_graph(&self) -> &StatisticalGraph {
471        &self.action_graph
472    }
473
474    pub fn day_graph(&self) -> &StatisticalGraph {
475        &self.day_graph
476    }
477
478    pub fn week_graph(&self) -> &StatisticalGraph {
479        &self.week_graph
480    }
481
482    pub fn top_senders(&self) -> &Vec<ChatStatisticsMessageSenderInfo> {
483        &self.top_senders
484    }
485
486    pub fn top_administrators(&self) -> &Vec<ChatStatisticsAdministratorActionsInfo> {
487        &self.top_administrators
488    }
489
490    pub fn top_inviters(&self) -> &Vec<ChatStatisticsInviterInfo> {
491        &self.top_inviters
492    }
493}
494
495#[doc(hidden)]
496pub struct ChatStatisticsSupergroupBuilder {
497    inner: ChatStatisticsSupergroup,
498}
499
500#[deprecated]
501pub type RTDChatStatisticsSupergroupBuilder = ChatStatisticsSupergroupBuilder;
502
503impl ChatStatisticsSupergroupBuilder {
504    pub fn build(&self) -> ChatStatisticsSupergroup {
505        self.inner.clone()
506    }
507
508    pub fn period<T: AsRef<DateRange>>(&mut self, period: T) -> &mut Self {
509        self.inner.period = period.as_ref().clone();
510        self
511    }
512
513    pub fn member_count<T: AsRef<StatisticalValue>>(&mut self, member_count: T) -> &mut Self {
514        self.inner.member_count = member_count.as_ref().clone();
515        self
516    }
517
518    pub fn message_count<T: AsRef<StatisticalValue>>(&mut self, message_count: T) -> &mut Self {
519        self.inner.message_count = message_count.as_ref().clone();
520        self
521    }
522
523    pub fn viewer_count<T: AsRef<StatisticalValue>>(&mut self, viewer_count: T) -> &mut Self {
524        self.inner.viewer_count = viewer_count.as_ref().clone();
525        self
526    }
527
528    pub fn sender_count<T: AsRef<StatisticalValue>>(&mut self, sender_count: T) -> &mut Self {
529        self.inner.sender_count = sender_count.as_ref().clone();
530        self
531    }
532
533    pub fn member_count_graph<T: AsRef<StatisticalGraph>>(
534        &mut self,
535        member_count_graph: T,
536    ) -> &mut Self {
537        self.inner.member_count_graph = member_count_graph.as_ref().clone();
538        self
539    }
540
541    pub fn join_graph<T: AsRef<StatisticalGraph>>(&mut self, join_graph: T) -> &mut Self {
542        self.inner.join_graph = join_graph.as_ref().clone();
543        self
544    }
545
546    pub fn join_by_source_graph<T: AsRef<StatisticalGraph>>(
547        &mut self,
548        join_by_source_graph: T,
549    ) -> &mut Self {
550        self.inner.join_by_source_graph = join_by_source_graph.as_ref().clone();
551        self
552    }
553
554    pub fn language_graph<T: AsRef<StatisticalGraph>>(&mut self, language_graph: T) -> &mut Self {
555        self.inner.language_graph = language_graph.as_ref().clone();
556        self
557    }
558
559    pub fn message_content_graph<T: AsRef<StatisticalGraph>>(
560        &mut self,
561        message_content_graph: T,
562    ) -> &mut Self {
563        self.inner.message_content_graph = message_content_graph.as_ref().clone();
564        self
565    }
566
567    pub fn action_graph<T: AsRef<StatisticalGraph>>(&mut self, action_graph: T) -> &mut Self {
568        self.inner.action_graph = action_graph.as_ref().clone();
569        self
570    }
571
572    pub fn day_graph<T: AsRef<StatisticalGraph>>(&mut self, day_graph: T) -> &mut Self {
573        self.inner.day_graph = day_graph.as_ref().clone();
574        self
575    }
576
577    pub fn week_graph<T: AsRef<StatisticalGraph>>(&mut self, week_graph: T) -> &mut Self {
578        self.inner.week_graph = week_graph.as_ref().clone();
579        self
580    }
581
582    pub fn top_senders(&mut self, top_senders: Vec<ChatStatisticsMessageSenderInfo>) -> &mut Self {
583        self.inner.top_senders = top_senders;
584        self
585    }
586
587    pub fn top_administrators(
588        &mut self,
589        top_administrators: Vec<ChatStatisticsAdministratorActionsInfo>,
590    ) -> &mut Self {
591        self.inner.top_administrators = top_administrators;
592        self
593    }
594
595    pub fn top_inviters(&mut self, top_inviters: Vec<ChatStatisticsInviterInfo>) -> &mut Self {
596        self.inner.top_inviters = top_inviters;
597        self
598    }
599}
600
601impl AsRef<ChatStatisticsSupergroup> for ChatStatisticsSupergroup {
602    fn as_ref(&self) -> &ChatStatisticsSupergroup {
603        self
604    }
605}
606
607impl AsRef<ChatStatisticsSupergroup> for ChatStatisticsSupergroupBuilder {
608    fn as_ref(&self) -> &ChatStatisticsSupergroup {
609        &self.inner
610    }
611}