tgbot/types/link/mod.rs
1use serde::{Deserialize, Serialize};
2
3#[cfg(test)]
4mod tests;
5
6/// Represents the options used for link preview generation.
7#[serde_with::skip_serializing_none]
8#[derive(Clone, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
9pub struct LinkPreviewOptions {
10 /// Whether the link preview is disabled.
11 pub is_disabled: Option<bool>,
12 /// Whether the media in the link preview is suppposed to be enlarged.
13 pub prefer_large_media: Option<bool>,
14 /// Whether the media in the link preview is suppposed to be shrunk.
15 pub prefer_small_media: Option<bool>,
16 /// Whether the link preview must be shown above the message text.
17 pub show_above_text: Option<bool>,
18 /// URL to use for the link preview.
19 pub url: Option<String>,
20}
21
22impl LinkPreviewOptions {
23 /// Sets a new value for the `is_disabled` flag.
24 ///
25 /// # Arguments
26 ///
27 /// * `value` - Whether the link preview is disabled.
28 pub fn with_is_disabled(mut self, value: bool) -> Self {
29 self.is_disabled = Some(value);
30 self
31 }
32
33 /// Sets a new value for the `prefer_large_media` flag.
34 ///
35 /// # Arguments
36 ///
37 /// * `value` - Whether the media in the link preview is suppposed to be enlarged;
38 /// ignored if the URL isn't explicitly specified or media size change isn't supported for the preview.
39 pub fn with_prefer_large_media(mut self, value: bool) -> Self {
40 self.prefer_large_media = Some(value);
41 self
42 }
43
44 /// Sets a new value for the `prefer_small_media` flag.
45 ///
46 /// # Arguments
47 ///
48 /// * `value` - Whether the media in the link preview is suppposed to be shrunk;
49 /// ignored if the URL isn't explicitly specified or media size change isn't supported for the preview.
50 pub fn with_prefer_small_media(mut self, value: bool) -> Self {
51 self.prefer_small_media = Some(value);
52 self
53 }
54
55 /// Sets a new value for the `show_above_text` flag.
56 ///
57 /// # Arguments
58 ///
59 /// * `value` - Whether the link preview must be shown above the message text;
60 /// otherwise, the link preview will be shown below the message text.
61 pub fn with_show_above_text(mut self, value: bool) -> Self {
62 self.show_above_text = Some(value);
63 self
64 }
65
66 /// Sets a new URL.
67 ///
68 /// # Arguments
69 ///
70 /// * `value` - URL to use for the link preview.
71 ///
72 /// If empty, then the first URL found in the message text will be used.
73 pub fn with_url<T>(mut self, value: T) -> Self
74 where
75 T: Into<String>,
76 {
77 self.url = Some(value.into());
78 self
79 }
80}