rust_tdlib/types/
web_page.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Describes a web page preview
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct WebPage {
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    /// Original URL of the link
14
15    #[serde(default)]
16    url: String,
17    /// URL to display
18
19    #[serde(default)]
20    display_url: String,
21    /// Type of the web page. Can be: article, photo, audio, video, document, profile, app, or something else
22
23    #[serde(rename(serialize = "type", deserialize = "type"))]
24    #[serde(default)]
25    type_: String,
26    /// Short name of the site (e.g., Google Docs, App Store)
27
28    #[serde(default)]
29    site_name: String,
30    /// Title of the content
31
32    #[serde(default)]
33    title: String,
34    /// Describes a web page preview
35    description: FormattedText,
36    /// Image representing the content; may be null
37    photo: Option<Photo>,
38    /// URL to show in the embedded preview
39
40    #[serde(default)]
41    embed_url: String,
42    /// MIME type of the embedded preview, (e.g., text/html or video/mp4)
43
44    #[serde(default)]
45    embed_type: String,
46    /// Width of the embedded preview
47
48    #[serde(default)]
49    embed_width: i32,
50    /// Height of the embedded preview
51
52    #[serde(default)]
53    embed_height: i32,
54    /// Duration of the content, in seconds
55
56    #[serde(default)]
57    duration: i32,
58    /// Author of the content
59
60    #[serde(default)]
61    author: String,
62    /// Preview of the content as an animation, if available; may be null
63    animation: Option<Animation>,
64    /// Preview of the content as an audio file, if available; may be null
65    audio: Option<Audio>,
66    /// Preview of the content as a document, if available; may be null
67    document: Option<Document>,
68    /// Preview of the content as a sticker for small WEBP files, if available; may be null
69    sticker: Option<Sticker>,
70    /// Preview of the content as a video, if available; may be null
71    video: Option<Video>,
72    /// Preview of the content as a video note, if available; may be null
73    video_note: Option<VideoNote>,
74    /// Preview of the content as a voice note, if available; may be null
75    voice_note: Option<VoiceNote>,
76    /// Version of instant view, available for the web page (currently, can be 1 or 2), 0 if none
77
78    #[serde(default)]
79    instant_view_version: i32,
80}
81
82impl RObject for WebPage {
83    #[doc(hidden)]
84    fn extra(&self) -> Option<&str> {
85        self.extra.as_deref()
86    }
87    #[doc(hidden)]
88    fn client_id(&self) -> Option<i32> {
89        self.client_id
90    }
91}
92
93impl WebPage {
94    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
95        Ok(serde_json::from_str(json.as_ref())?)
96    }
97    pub fn builder() -> WebPageBuilder {
98        let mut inner = WebPage::default();
99        inner.extra = Some(Uuid::new_v4().to_string());
100
101        WebPageBuilder { inner }
102    }
103
104    pub fn url(&self) -> &String {
105        &self.url
106    }
107
108    pub fn display_url(&self) -> &String {
109        &self.display_url
110    }
111
112    pub fn type_(&self) -> &String {
113        &self.type_
114    }
115
116    pub fn site_name(&self) -> &String {
117        &self.site_name
118    }
119
120    pub fn title(&self) -> &String {
121        &self.title
122    }
123
124    pub fn description(&self) -> &FormattedText {
125        &self.description
126    }
127
128    pub fn photo(&self) -> &Option<Photo> {
129        &self.photo
130    }
131
132    pub fn embed_url(&self) -> &String {
133        &self.embed_url
134    }
135
136    pub fn embed_type(&self) -> &String {
137        &self.embed_type
138    }
139
140    pub fn embed_width(&self) -> i32 {
141        self.embed_width
142    }
143
144    pub fn embed_height(&self) -> i32 {
145        self.embed_height
146    }
147
148    pub fn duration(&self) -> i32 {
149        self.duration
150    }
151
152    pub fn author(&self) -> &String {
153        &self.author
154    }
155
156    pub fn animation(&self) -> &Option<Animation> {
157        &self.animation
158    }
159
160    pub fn audio(&self) -> &Option<Audio> {
161        &self.audio
162    }
163
164    pub fn document(&self) -> &Option<Document> {
165        &self.document
166    }
167
168    pub fn sticker(&self) -> &Option<Sticker> {
169        &self.sticker
170    }
171
172    pub fn video(&self) -> &Option<Video> {
173        &self.video
174    }
175
176    pub fn video_note(&self) -> &Option<VideoNote> {
177        &self.video_note
178    }
179
180    pub fn voice_note(&self) -> &Option<VoiceNote> {
181        &self.voice_note
182    }
183
184    pub fn instant_view_version(&self) -> i32 {
185        self.instant_view_version
186    }
187}
188
189#[doc(hidden)]
190pub struct WebPageBuilder {
191    inner: WebPage,
192}
193
194#[deprecated]
195pub type RTDWebPageBuilder = WebPageBuilder;
196
197impl WebPageBuilder {
198    pub fn build(&self) -> WebPage {
199        self.inner.clone()
200    }
201
202    pub fn url<T: AsRef<str>>(&mut self, url: T) -> &mut Self {
203        self.inner.url = url.as_ref().to_string();
204        self
205    }
206
207    pub fn display_url<T: AsRef<str>>(&mut self, display_url: T) -> &mut Self {
208        self.inner.display_url = display_url.as_ref().to_string();
209        self
210    }
211
212    pub fn type_<T: AsRef<str>>(&mut self, type_: T) -> &mut Self {
213        self.inner.type_ = type_.as_ref().to_string();
214        self
215    }
216
217    pub fn site_name<T: AsRef<str>>(&mut self, site_name: T) -> &mut Self {
218        self.inner.site_name = site_name.as_ref().to_string();
219        self
220    }
221
222    pub fn title<T: AsRef<str>>(&mut self, title: T) -> &mut Self {
223        self.inner.title = title.as_ref().to_string();
224        self
225    }
226
227    pub fn description<T: AsRef<FormattedText>>(&mut self, description: T) -> &mut Self {
228        self.inner.description = description.as_ref().clone();
229        self
230    }
231
232    pub fn photo<T: AsRef<Photo>>(&mut self, photo: T) -> &mut Self {
233        self.inner.photo = Some(photo.as_ref().clone());
234        self
235    }
236
237    pub fn embed_url<T: AsRef<str>>(&mut self, embed_url: T) -> &mut Self {
238        self.inner.embed_url = embed_url.as_ref().to_string();
239        self
240    }
241
242    pub fn embed_type<T: AsRef<str>>(&mut self, embed_type: T) -> &mut Self {
243        self.inner.embed_type = embed_type.as_ref().to_string();
244        self
245    }
246
247    pub fn embed_width(&mut self, embed_width: i32) -> &mut Self {
248        self.inner.embed_width = embed_width;
249        self
250    }
251
252    pub fn embed_height(&mut self, embed_height: i32) -> &mut Self {
253        self.inner.embed_height = embed_height;
254        self
255    }
256
257    pub fn duration(&mut self, duration: i32) -> &mut Self {
258        self.inner.duration = duration;
259        self
260    }
261
262    pub fn author<T: AsRef<str>>(&mut self, author: T) -> &mut Self {
263        self.inner.author = author.as_ref().to_string();
264        self
265    }
266
267    pub fn animation<T: AsRef<Animation>>(&mut self, animation: T) -> &mut Self {
268        self.inner.animation = Some(animation.as_ref().clone());
269        self
270    }
271
272    pub fn audio<T: AsRef<Audio>>(&mut self, audio: T) -> &mut Self {
273        self.inner.audio = Some(audio.as_ref().clone());
274        self
275    }
276
277    pub fn document<T: AsRef<Document>>(&mut self, document: T) -> &mut Self {
278        self.inner.document = Some(document.as_ref().clone());
279        self
280    }
281
282    pub fn sticker<T: AsRef<Sticker>>(&mut self, sticker: T) -> &mut Self {
283        self.inner.sticker = Some(sticker.as_ref().clone());
284        self
285    }
286
287    pub fn video<T: AsRef<Video>>(&mut self, video: T) -> &mut Self {
288        self.inner.video = Some(video.as_ref().clone());
289        self
290    }
291
292    pub fn video_note<T: AsRef<VideoNote>>(&mut self, video_note: T) -> &mut Self {
293        self.inner.video_note = Some(video_note.as_ref().clone());
294        self
295    }
296
297    pub fn voice_note<T: AsRef<VoiceNote>>(&mut self, voice_note: T) -> &mut Self {
298        self.inner.voice_note = Some(voice_note.as_ref().clone());
299        self
300    }
301
302    pub fn instant_view_version(&mut self, instant_view_version: i32) -> &mut Self {
303        self.inner.instant_view_version = instant_view_version;
304        self
305    }
306}
307
308impl AsRef<WebPage> for WebPage {
309    fn as_ref(&self) -> &WebPage {
310        self
311    }
312}
313
314impl AsRef<WebPage> for WebPageBuilder {
315    fn as_ref(&self) -> &WebPage {
316        &self.inner
317    }
318}