1use serde::{Deserialize, Serialize};
2
3use crate::chat::{
4 ApproveChatJoinRequest, BanChatMember, ChatId, ChatPermissions, DeclineChatJoinRequest,
5 GetChatMember, PromoteChatMember, RestrictChatMember, SetChatAdministratorCustomTitle,
6 UnbanChatMember,
7};
8use crate::file::PhotoSize;
9use crate::{JsonMethod, TelegramMethod};
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct User {
14 pub id: i64,
16 pub is_bot: bool,
18 pub first_name: String,
20 #[serde(skip_serializing_if = "Option::is_none")]
22 pub last_name: Option<String>,
23 #[serde(skip_serializing_if = "Option::is_none")]
25 pub username: Option<String>,
26 #[serde(skip_serializing_if = "Option::is_none")]
28 pub language_code: Option<String>,
29 #[serde(skip_serializing_if = "Option::is_none")]
32 pub can_join_groups: Option<bool>,
33 #[serde(skip_serializing_if = "Option::is_none")]
36 pub can_read_all_group_messages: Option<bool>,
37 #[serde(skip_serializing_if = "Option::is_none")]
40 pub supports_inline_queries: Option<bool>,
41}
42
43impl User {
44 pub fn get_profile_photos(&self) -> GetUserProfilePhotos {
45 GetUserProfilePhotos::new(self.id)
46 }
47
48 pub fn ban_from(&self, chat_id: impl Into<ChatId>) -> BanChatMember {
49 BanChatMember::new(chat_id, self.id)
50 }
51
52 pub fn unban_from(&self, chat_id: impl Into<ChatId>) -> UnbanChatMember {
53 UnbanChatMember::new(chat_id, self.id)
54 }
55
56 pub fn restrict_from(
57 &self,
58 chat_id: impl Into<ChatId>,
59 permissions: ChatPermissions,
60 ) -> RestrictChatMember {
61 RestrictChatMember::new(chat_id, self.id, permissions)
62 }
63
64 pub fn promote_from(&self, chat_id: impl Into<ChatId>) -> PromoteChatMember {
65 PromoteChatMember::new(chat_id, self.id)
66 }
67
68 pub fn set_administrator_title_from(
69 &self,
70 chat_id: impl Into<ChatId>,
71 custom_title: impl Into<String>,
72 ) -> SetChatAdministratorCustomTitle {
73 SetChatAdministratorCustomTitle::new(chat_id, self.id, custom_title)
74 }
75
76 pub fn approve_join_to(&self, chat_id: impl Into<ChatId>) -> ApproveChatJoinRequest {
77 ApproveChatJoinRequest::new(chat_id, self.id)
78 }
79
80 pub fn decline_join_to(&self, chat_id: impl Into<ChatId>) -> DeclineChatJoinRequest {
81 DeclineChatJoinRequest::new(chat_id, self.id)
82 }
83
84 pub fn get_member_from(&self, chat_id: impl Into<ChatId>) -> GetChatMember {
85 GetChatMember::new(chat_id, self.id)
86 }
87}
88
89#[derive(Debug, Deserialize)]
91pub struct UserProfilePhotos {
92 pub total_count: usize,
94 pub photos: Vec<Vec<PhotoSize>>,
96}
97
98#[derive(Clone, Serialize)]
101pub struct GetUserProfilePhotos {
102 user_id: i64,
104 #[serde(skip_serializing_if = "Option::is_none")]
106 offset: Option<u32>,
107 #[serde(skip_serializing_if = "Option::is_none")]
109 limit: Option<u32>,
110}
111
112impl GetUserProfilePhotos {
113 pub fn new(user_id: i64) -> Self {
115 Self {
116 user_id,
117 offset: None,
118 limit: None,
119 }
120 }
121 pub fn with_offset(self, offset: u32) -> Self {
123 Self {
124 offset: Some(offset),
125 ..self
126 }
127 }
128 pub fn with_limit(self, limit: u32) -> Self {
130 Self {
131 limit: Some(limit),
132 ..self
133 }
134 }
135}
136
137impl TelegramMethod for GetUserProfilePhotos {
138 type Response = UserProfilePhotos;
139
140 fn name() -> &'static str {
141 "getUserProfilePhotos"
142 }
143}
144
145impl JsonMethod for GetUserProfilePhotos {}