rtdlib/types/
message_statistics.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// A detailed statistics about a message
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct MessageStatistics {
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  /// A graph containing number of message views and shares
19  message_interaction_graph: StatisticalGraph,
20  
21}
22
23impl RObject for MessageStatistics {
24  #[doc(hidden)] fn td_name(&self) -> &'static str { "messageStatistics" }
25  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
26  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
27}
28
29
30
31impl MessageStatistics {
32  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
33  pub fn builder() -> RTDMessageStatisticsBuilder {
34    let mut inner = MessageStatistics::default();
35    inner.td_name = "messageStatistics".to_string();
36    inner.extra = Some(Uuid::new_v4().to_string());
37    RTDMessageStatisticsBuilder { inner }
38  }
39
40  pub fn message_interaction_graph(&self) -> &StatisticalGraph { &self.message_interaction_graph }
41
42}
43
44#[doc(hidden)]
45pub struct RTDMessageStatisticsBuilder {
46  inner: MessageStatistics
47}
48
49impl RTDMessageStatisticsBuilder {
50  pub fn build(&self) -> MessageStatistics { self.inner.clone() }
51
52   
53  pub fn message_interaction_graph<T: AsRef<StatisticalGraph>>(&mut self, message_interaction_graph: T) -> &mut Self {
54    self.inner.message_interaction_graph = message_interaction_graph.as_ref().clone();
55    self
56  }
57
58}
59
60impl AsRef<MessageStatistics> for MessageStatistics {
61  fn as_ref(&self) -> &MessageStatistics { self }
62}
63
64impl AsRef<MessageStatistics> for RTDMessageStatisticsBuilder {
65  fn as_ref(&self) -> &MessageStatistics { &self.inner }
66}
67
68
69