rust_tdlib/types/
video_chat.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Describes a video chat
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct VideoChat {
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    /// Group call identifier of an active video chat; 0 if none. Full information about the video chat can be received through the method getGroupCall
14
15    #[serde(default)]
16    group_call_id: i32,
17    /// True, if the video chat has participants
18
19    #[serde(default)]
20    has_participants: bool,
21    /// Default group call participant identifier to join the video chat; may be null
22    default_participant_id: Option<MessageSender>,
23}
24
25impl RObject for VideoChat {
26    #[doc(hidden)]
27    fn extra(&self) -> Option<&str> {
28        self.extra.as_deref()
29    }
30    #[doc(hidden)]
31    fn client_id(&self) -> Option<i32> {
32        self.client_id
33    }
34}
35
36impl VideoChat {
37    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
38        Ok(serde_json::from_str(json.as_ref())?)
39    }
40    pub fn builder() -> VideoChatBuilder {
41        let mut inner = VideoChat::default();
42        inner.extra = Some(Uuid::new_v4().to_string());
43
44        VideoChatBuilder { inner }
45    }
46
47    pub fn group_call_id(&self) -> i32 {
48        self.group_call_id
49    }
50
51    pub fn has_participants(&self) -> bool {
52        self.has_participants
53    }
54
55    pub fn default_participant_id(&self) -> &Option<MessageSender> {
56        &self.default_participant_id
57    }
58}
59
60#[doc(hidden)]
61pub struct VideoChatBuilder {
62    inner: VideoChat,
63}
64
65#[deprecated]
66pub type RTDVideoChatBuilder = VideoChatBuilder;
67
68impl VideoChatBuilder {
69    pub fn build(&self) -> VideoChat {
70        self.inner.clone()
71    }
72
73    pub fn group_call_id(&mut self, group_call_id: i32) -> &mut Self {
74        self.inner.group_call_id = group_call_id;
75        self
76    }
77
78    pub fn has_participants(&mut self, has_participants: bool) -> &mut Self {
79        self.inner.has_participants = has_participants;
80        self
81    }
82
83    pub fn default_participant_id<T: AsRef<MessageSender>>(
84        &mut self,
85        default_participant_id: T,
86    ) -> &mut Self {
87        self.inner.default_participant_id = Some(default_participant_id.as_ref().clone());
88        self
89    }
90}
91
92impl AsRef<VideoChat> for VideoChat {
93    fn as_ref(&self) -> &VideoChat {
94        self
95    }
96}
97
98impl AsRef<VideoChat> for VideoChatBuilder {
99    fn as_ref(&self) -> &VideoChat {
100        &self.inner
101    }
102}