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