rust_tdlib/types/
input_chat_photo.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7/// Describes a photo to be set as a user profile or chat photo
8pub trait TDInputChatPhoto: Debug + RObject {}
9
10/// Describes a photo to be set as a user profile or chat photo
11#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum InputChatPhoto {
14    #[doc(hidden)]
15    #[default]
16    _Default,
17    /// An animation in MPEG4 format; must be square, at most 10 seconds long, have width between 160 and 800 and be at most 2MB in size
18    #[serde(rename = "inputChatPhotoAnimation")]
19    Animation(InputChatPhotoAnimation),
20    /// A previously used profile photo of the current user
21    #[serde(rename = "inputChatPhotoPrevious")]
22    Previous(InputChatPhotoPrevious),
23    /// A static photo in JPEG format
24    #[serde(rename = "inputChatPhotoStatic")]
25    Static(InputChatPhotoStatic),
26}
27
28impl RObject for InputChatPhoto {
29    #[doc(hidden)]
30    fn extra(&self) -> Option<&str> {
31        match self {
32            InputChatPhoto::Animation(t) => t.extra(),
33            InputChatPhoto::Previous(t) => t.extra(),
34            InputChatPhoto::Static(t) => t.extra(),
35
36            _ => None,
37        }
38    }
39    #[doc(hidden)]
40    fn client_id(&self) -> Option<i32> {
41        match self {
42            InputChatPhoto::Animation(t) => t.client_id(),
43            InputChatPhoto::Previous(t) => t.client_id(),
44            InputChatPhoto::Static(t) => t.client_id(),
45
46            _ => None,
47        }
48    }
49}
50
51impl InputChatPhoto {
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, InputChatPhoto::_Default)
58    }
59}
60
61impl AsRef<InputChatPhoto> for InputChatPhoto {
62    fn as_ref(&self) -> &InputChatPhoto {
63        self
64    }
65}
66
67/// An animation in MPEG4 format; must be square, at most 10 seconds long, have width between 160 and 800 and be at most 2MB in size
68#[derive(Debug, Clone, Default, Serialize, Deserialize)]
69pub struct InputChatPhotoAnimation {
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    /// Animation to be set as profile photo. Only inputFileLocal and inputFileGenerated are allowed
76
77    #[serde(skip_serializing_if = "InputFile::_is_default")]
78    animation: InputFile,
79    /// Timestamp of the frame, which will be used as static chat photo
80
81    #[serde(default)]
82    main_frame_timestamp: f32,
83}
84
85impl RObject for InputChatPhotoAnimation {
86    #[doc(hidden)]
87    fn extra(&self) -> Option<&str> {
88        self.extra.as_deref()
89    }
90    #[doc(hidden)]
91    fn client_id(&self) -> Option<i32> {
92        self.client_id
93    }
94}
95
96impl TDInputChatPhoto for InputChatPhotoAnimation {}
97
98impl InputChatPhotoAnimation {
99    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
100        Ok(serde_json::from_str(json.as_ref())?)
101    }
102    pub fn builder() -> InputChatPhotoAnimationBuilder {
103        let mut inner = InputChatPhotoAnimation::default();
104        inner.extra = Some(Uuid::new_v4().to_string());
105
106        InputChatPhotoAnimationBuilder { inner }
107    }
108
109    pub fn animation(&self) -> &InputFile {
110        &self.animation
111    }
112
113    pub fn main_frame_timestamp(&self) -> f32 {
114        self.main_frame_timestamp
115    }
116}
117
118#[doc(hidden)]
119pub struct InputChatPhotoAnimationBuilder {
120    inner: InputChatPhotoAnimation,
121}
122
123#[deprecated]
124pub type RTDInputChatPhotoAnimationBuilder = InputChatPhotoAnimationBuilder;
125
126impl InputChatPhotoAnimationBuilder {
127    pub fn build(&self) -> InputChatPhotoAnimation {
128        self.inner.clone()
129    }
130
131    pub fn animation<T: AsRef<InputFile>>(&mut self, animation: T) -> &mut Self {
132        self.inner.animation = animation.as_ref().clone();
133        self
134    }
135
136    pub fn main_frame_timestamp(&mut self, main_frame_timestamp: f32) -> &mut Self {
137        self.inner.main_frame_timestamp = main_frame_timestamp;
138        self
139    }
140}
141
142impl AsRef<InputChatPhotoAnimation> for InputChatPhotoAnimation {
143    fn as_ref(&self) -> &InputChatPhotoAnimation {
144        self
145    }
146}
147
148impl AsRef<InputChatPhotoAnimation> for InputChatPhotoAnimationBuilder {
149    fn as_ref(&self) -> &InputChatPhotoAnimation {
150        &self.inner
151    }
152}
153
154/// A previously used profile photo of the current user
155#[derive(Debug, Clone, Default, Serialize, Deserialize)]
156pub struct InputChatPhotoPrevious {
157    #[doc(hidden)]
158    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
159    extra: Option<String>,
160    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
161    client_id: Option<i32>,
162    /// Identifier of the current user's profile photo to reuse
163
164    #[serde(
165        deserialize_with = "super::_common::number_from_string",
166        serialize_with = "super::_common::string_to_number"
167    )]
168    #[serde(default)]
169    chat_photo_id: i64,
170}
171
172impl RObject for InputChatPhotoPrevious {
173    #[doc(hidden)]
174    fn extra(&self) -> Option<&str> {
175        self.extra.as_deref()
176    }
177    #[doc(hidden)]
178    fn client_id(&self) -> Option<i32> {
179        self.client_id
180    }
181}
182
183impl TDInputChatPhoto for InputChatPhotoPrevious {}
184
185impl InputChatPhotoPrevious {
186    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
187        Ok(serde_json::from_str(json.as_ref())?)
188    }
189    pub fn builder() -> InputChatPhotoPreviousBuilder {
190        let mut inner = InputChatPhotoPrevious::default();
191        inner.extra = Some(Uuid::new_v4().to_string());
192
193        InputChatPhotoPreviousBuilder { inner }
194    }
195
196    pub fn chat_photo_id(&self) -> i64 {
197        self.chat_photo_id
198    }
199}
200
201#[doc(hidden)]
202pub struct InputChatPhotoPreviousBuilder {
203    inner: InputChatPhotoPrevious,
204}
205
206#[deprecated]
207pub type RTDInputChatPhotoPreviousBuilder = InputChatPhotoPreviousBuilder;
208
209impl InputChatPhotoPreviousBuilder {
210    pub fn build(&self) -> InputChatPhotoPrevious {
211        self.inner.clone()
212    }
213
214    pub fn chat_photo_id(&mut self, chat_photo_id: i64) -> &mut Self {
215        self.inner.chat_photo_id = chat_photo_id;
216        self
217    }
218}
219
220impl AsRef<InputChatPhotoPrevious> for InputChatPhotoPrevious {
221    fn as_ref(&self) -> &InputChatPhotoPrevious {
222        self
223    }
224}
225
226impl AsRef<InputChatPhotoPrevious> for InputChatPhotoPreviousBuilder {
227    fn as_ref(&self) -> &InputChatPhotoPrevious {
228        &self.inner
229    }
230}
231
232/// A static photo in JPEG format
233#[derive(Debug, Clone, Default, Serialize, Deserialize)]
234pub struct InputChatPhotoStatic {
235    #[doc(hidden)]
236    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
237    extra: Option<String>,
238    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
239    client_id: Option<i32>,
240    /// Photo to be set as profile photo. Only inputFileLocal and inputFileGenerated are allowed
241
242    #[serde(skip_serializing_if = "InputFile::_is_default")]
243    photo: InputFile,
244}
245
246impl RObject for InputChatPhotoStatic {
247    #[doc(hidden)]
248    fn extra(&self) -> Option<&str> {
249        self.extra.as_deref()
250    }
251    #[doc(hidden)]
252    fn client_id(&self) -> Option<i32> {
253        self.client_id
254    }
255}
256
257impl TDInputChatPhoto for InputChatPhotoStatic {}
258
259impl InputChatPhotoStatic {
260    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
261        Ok(serde_json::from_str(json.as_ref())?)
262    }
263    pub fn builder() -> InputChatPhotoStaticBuilder {
264        let mut inner = InputChatPhotoStatic::default();
265        inner.extra = Some(Uuid::new_v4().to_string());
266
267        InputChatPhotoStaticBuilder { inner }
268    }
269
270    pub fn photo(&self) -> &InputFile {
271        &self.photo
272    }
273}
274
275#[doc(hidden)]
276pub struct InputChatPhotoStaticBuilder {
277    inner: InputChatPhotoStatic,
278}
279
280#[deprecated]
281pub type RTDInputChatPhotoStaticBuilder = InputChatPhotoStaticBuilder;
282
283impl InputChatPhotoStaticBuilder {
284    pub fn build(&self) -> InputChatPhotoStatic {
285        self.inner.clone()
286    }
287
288    pub fn photo<T: AsRef<InputFile>>(&mut self, photo: T) -> &mut Self {
289        self.inner.photo = photo.as_ref().clone();
290        self
291    }
292}
293
294impl AsRef<InputChatPhotoStatic> for InputChatPhotoStatic {
295    fn as_ref(&self) -> &InputChatPhotoStatic {
296        self
297    }
298}
299
300impl AsRef<InputChatPhotoStatic> for InputChatPhotoStaticBuilder {
301    fn as_ref(&self) -> &InputChatPhotoStatic {
302        &self.inner
303    }
304}