tgbot/types/definitions/chat/
photo.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    api::{Form, Method, Payload},
5    types::{ChatId, InputFile},
6};
7
8/// Represents a chat photo.
9#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
10pub struct ChatPhoto {
11    /// File identifier of a big (640x640) chat photo.
12    ///
13    /// Can be used only for photo download and only for as long as the photo is not changed.
14    pub big_file_id: String,
15    /// Unique file identifier of a big (640x640) chat photo.
16    ///
17    /// It is supposed to be the same over time and for different bots.
18    /// Can't be used to download or reuse the file.
19    pub big_file_unique_id: String,
20    /// File identifier of a small (160x160) chat photo.
21    ///
22    /// Can be used only for photo download and only for as long as the photo is not changed.
23    pub small_file_id: String,
24    /// Unique file identifier of a small (160x160) chat photo.
25    ///
26    /// It is supposed to be the same over time and for different bots.
27    /// Can't be used to download or reuse the file.
28    pub small_file_unique_id: String,
29}
30
31impl ChatPhoto {
32    /// Creates a new `ChatPhoto`.
33    ///
34    /// # Arguments
35    ///
36    /// * `big_file_id` - File identifier of a big (640x640) chat photo.
37    /// * `big_file_unique_id` - Unique file identifier of a big (640x640) chat photo.
38    /// * `small_file_id` - File identifier of a small (160x160) chat photo.
39    /// * `small_file_unique_id` - Unique file identifier of a small (160x160) chat photo.
40    pub fn new<A, B, C, D>(big_file_id: A, big_file_unique_id: B, small_file_id: C, small_file_unique_id: D) -> Self
41    where
42        A: Into<String>,
43        B: Into<String>,
44        C: Into<String>,
45        D: Into<String>,
46    {
47        Self {
48            big_file_id: big_file_id.into(),
49            big_file_unique_id: big_file_unique_id.into(),
50            small_file_id: small_file_id.into(),
51            small_file_unique_id: small_file_unique_id.into(),
52        }
53    }
54}
55
56/// Deletes a chat photo.
57///
58/// Photos can't be changed for private chats.
59/// The bot must be an administrator in the chat for this
60/// to work and must have the appropriate admin rights.
61///
62/// #  Notes
63///
64/// In regular groups (non-supergroups), this method
65/// will only work if the ‘All Members Are Admins’
66/// setting is off in the target group.
67#[derive(Clone, Debug, Serialize)]
68pub struct DeleteChatPhoto {
69    chat_id: ChatId,
70}
71
72impl DeleteChatPhoto {
73    /// Creates a new `DeleteChatPhoto`.
74    ///
75    /// # Arguments
76    ///
77    /// * `chat_id` - Unique identifier of the target chat.
78    pub fn new<T>(chat_id: T) -> Self
79    where
80        T: Into<ChatId>,
81    {
82        DeleteChatPhoto {
83            chat_id: chat_id.into(),
84        }
85    }
86}
87
88impl Method for DeleteChatPhoto {
89    type Response = bool;
90
91    fn into_payload(self) -> Payload {
92        Payload::json("deleteChatPhoto", self)
93    }
94}
95
96/// Sets a new profile photo for a chat.
97///
98/// Photos can't be changed for private chats
99/// The bot must be an administrator in the chat for this to work
100/// and must have the appropriate admin rights.
101///
102/// # Notes
103///
104/// In regular groups (non-supergroups), this method will only work
105/// if the ‘All Members Are Admins’ setting is off in the target group.
106#[derive(Debug)]
107pub struct SetChatPhoto {
108    form: Form,
109}
110
111impl SetChatPhoto {
112    /// Creates a new `SetChatPhoto`.
113    ///
114    /// # Arguments
115    ///
116    /// * `chat_id` - Unique identifier of the target chat.
117    /// * `photo` - New chat photo, uploaded using `multipart/form-data`
118    ///   (url and file_id are not supported).
119    pub fn new<A, B>(chat_id: A, photo: B) -> Self
120    where
121        A: Into<ChatId>,
122        B: Into<InputFile>,
123    {
124        Self {
125            form: Form::from([("chat_id", chat_id.into().into()), ("photo", photo.into().into())]),
126        }
127    }
128}
129
130impl Method for SetChatPhoto {
131    type Response = bool;
132
133    fn into_payload(self) -> Payload {
134        Payload::form("setChatPhoto", self.form)
135    }
136}