rust_tdlib/types/
discard_call.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Discards a call
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct DiscardCall {
8    #[doc(hidden)]
9    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10    extra: Option<String>,
11    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12    client_id: Option<i32>,
13    /// Call identifier
14
15    #[serde(default)]
16    call_id: i32,
17    /// True, if the user was disconnected
18
19    #[serde(default)]
20    is_disconnected: bool,
21    /// The call duration, in seconds
22
23    #[serde(default)]
24    duration: i32,
25    /// True, if the call was a video call
26
27    #[serde(default)]
28    is_video: bool,
29    /// Identifier of the connection used during the call
30
31    #[serde(
32        deserialize_with = "super::_common::number_from_string",
33        serialize_with = "super::_common::string_to_number"
34    )]
35    #[serde(default)]
36    connection_id: i64,
37
38    #[serde(rename(serialize = "@type"))]
39    td_type: String,
40}
41
42impl RObject for DiscardCall {
43    #[doc(hidden)]
44    fn extra(&self) -> Option<&str> {
45        self.extra.as_deref()
46    }
47    #[doc(hidden)]
48    fn client_id(&self) -> Option<i32> {
49        self.client_id
50    }
51}
52
53impl RFunction for DiscardCall {}
54
55impl DiscardCall {
56    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
57        Ok(serde_json::from_str(json.as_ref())?)
58    }
59    pub fn builder() -> DiscardCallBuilder {
60        let mut inner = DiscardCall::default();
61        inner.extra = Some(Uuid::new_v4().to_string());
62
63        inner.td_type = "discardCall".to_string();
64
65        DiscardCallBuilder { inner }
66    }
67
68    pub fn call_id(&self) -> i32 {
69        self.call_id
70    }
71
72    pub fn is_disconnected(&self) -> bool {
73        self.is_disconnected
74    }
75
76    pub fn duration(&self) -> i32 {
77        self.duration
78    }
79
80    pub fn is_video(&self) -> bool {
81        self.is_video
82    }
83
84    pub fn connection_id(&self) -> i64 {
85        self.connection_id
86    }
87}
88
89#[doc(hidden)]
90pub struct DiscardCallBuilder {
91    inner: DiscardCall,
92}
93
94#[deprecated]
95pub type RTDDiscardCallBuilder = DiscardCallBuilder;
96
97impl DiscardCallBuilder {
98    pub fn build(&self) -> DiscardCall {
99        self.inner.clone()
100    }
101
102    pub fn call_id(&mut self, call_id: i32) -> &mut Self {
103        self.inner.call_id = call_id;
104        self
105    }
106
107    pub fn is_disconnected(&mut self, is_disconnected: bool) -> &mut Self {
108        self.inner.is_disconnected = is_disconnected;
109        self
110    }
111
112    pub fn duration(&mut self, duration: i32) -> &mut Self {
113        self.inner.duration = duration;
114        self
115    }
116
117    pub fn is_video(&mut self, is_video: bool) -> &mut Self {
118        self.inner.is_video = is_video;
119        self
120    }
121
122    pub fn connection_id(&mut self, connection_id: i64) -> &mut Self {
123        self.inner.connection_id = connection_id;
124        self
125    }
126}
127
128impl AsRef<DiscardCall> for DiscardCall {
129    fn as_ref(&self) -> &DiscardCall {
130        self
131    }
132}
133
134impl AsRef<DiscardCall> for DiscardCallBuilder {
135    fn as_ref(&self) -> &DiscardCall {
136        &self.inner
137    }
138}