rust_tdlib/types/
join_group_call.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Joins an active group call. Returns join response payload for tgcalls
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct JoinGroupCall {
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
14
15    #[serde(default)]
16    group_call_id: i32,
17    /// Identifier of a group call participant, which will be used to join the call; pass null to join as self; video chats only
18
19    #[serde(skip_serializing_if = "MessageSender::_is_default")]
20    participant_id: MessageSender,
21    /// Caller audio channel synchronization source identifier; received from tgcalls
22
23    #[serde(default)]
24    audio_source_id: i32,
25    /// Group call join payload; received from tgcalls
26
27    #[serde(default)]
28    payload: String,
29    /// True, if the user's microphone is muted
30
31    #[serde(default)]
32    is_muted: bool,
33    /// True, if the user's video is enabled
34
35    #[serde(default)]
36    is_my_video_enabled: bool,
37    /// If non-empty, invite hash to be used to join the group call without being muted by administrators
38
39    #[serde(default)]
40    invite_hash: String,
41
42    #[serde(rename(serialize = "@type"))]
43    td_type: String,
44}
45
46impl RObject for JoinGroupCall {
47    #[doc(hidden)]
48    fn extra(&self) -> Option<&str> {
49        self.extra.as_deref()
50    }
51    #[doc(hidden)]
52    fn client_id(&self) -> Option<i32> {
53        self.client_id
54    }
55}
56
57impl RFunction for JoinGroupCall {}
58
59impl JoinGroupCall {
60    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
61        Ok(serde_json::from_str(json.as_ref())?)
62    }
63    pub fn builder() -> JoinGroupCallBuilder {
64        let mut inner = JoinGroupCall::default();
65        inner.extra = Some(Uuid::new_v4().to_string());
66
67        inner.td_type = "joinGroupCall".to_string();
68
69        JoinGroupCallBuilder { inner }
70    }
71
72    pub fn group_call_id(&self) -> i32 {
73        self.group_call_id
74    }
75
76    pub fn participant_id(&self) -> &MessageSender {
77        &self.participant_id
78    }
79
80    pub fn audio_source_id(&self) -> i32 {
81        self.audio_source_id
82    }
83
84    pub fn payload(&self) -> &String {
85        &self.payload
86    }
87
88    pub fn is_muted(&self) -> bool {
89        self.is_muted
90    }
91
92    pub fn is_my_video_enabled(&self) -> bool {
93        self.is_my_video_enabled
94    }
95
96    pub fn invite_hash(&self) -> &String {
97        &self.invite_hash
98    }
99}
100
101#[doc(hidden)]
102pub struct JoinGroupCallBuilder {
103    inner: JoinGroupCall,
104}
105
106#[deprecated]
107pub type RTDJoinGroupCallBuilder = JoinGroupCallBuilder;
108
109impl JoinGroupCallBuilder {
110    pub fn build(&self) -> JoinGroupCall {
111        self.inner.clone()
112    }
113
114    pub fn group_call_id(&mut self, group_call_id: i32) -> &mut Self {
115        self.inner.group_call_id = group_call_id;
116        self
117    }
118
119    pub fn participant_id<T: AsRef<MessageSender>>(&mut self, participant_id: T) -> &mut Self {
120        self.inner.participant_id = participant_id.as_ref().clone();
121        self
122    }
123
124    pub fn audio_source_id(&mut self, audio_source_id: i32) -> &mut Self {
125        self.inner.audio_source_id = audio_source_id;
126        self
127    }
128
129    pub fn payload<T: AsRef<str>>(&mut self, payload: T) -> &mut Self {
130        self.inner.payload = payload.as_ref().to_string();
131        self
132    }
133
134    pub fn is_muted(&mut self, is_muted: bool) -> &mut Self {
135        self.inner.is_muted = is_muted;
136        self
137    }
138
139    pub fn is_my_video_enabled(&mut self, is_my_video_enabled: bool) -> &mut Self {
140        self.inner.is_my_video_enabled = is_my_video_enabled;
141        self
142    }
143
144    pub fn invite_hash<T: AsRef<str>>(&mut self, invite_hash: T) -> &mut Self {
145        self.inner.invite_hash = invite_hash.as_ref().to_string();
146        self
147    }
148}
149
150impl AsRef<JoinGroupCall> for JoinGroupCall {
151    fn as_ref(&self) -> &JoinGroupCall {
152        self
153    }
154}
155
156impl AsRef<JoinGroupCall> for JoinGroupCallBuilder {
157    fn as_ref(&self) -> &JoinGroupCall {
158        &self.inner
159    }
160}