use serde::{Deserialize, Serialize};
use crate::chat::{
ApproveChatJoinRequest, BanChatMember, ChatId, ChatPermissions, DeclineChatJoinRequest,
GetChatMember, PromoteChatMember, RestrictChatMember, SetChatAdministratorCustomTitle,
UnbanChatMember,
};
use crate::file::PhotoSize;
use crate::{JsonMethod, TelegramMethod};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User {
pub id: i64,
pub is_bot: bool,
pub first_name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub username: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_join_groups: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub can_read_all_group_messages: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub supports_inline_queries: Option<bool>,
}
impl User {
pub fn get_profile_photos(&self) -> GetUserProfilePhotos {
GetUserProfilePhotos::new(self.id)
}
pub fn ban_from(&self, chat_id: impl Into<ChatId>) -> BanChatMember {
BanChatMember::new(chat_id, self.id)
}
pub fn unban_from(&self, chat_id: impl Into<ChatId>) -> UnbanChatMember {
UnbanChatMember::new(chat_id, self.id)
}
pub fn restrict_from(
&self,
chat_id: impl Into<ChatId>,
permissions: ChatPermissions,
) -> RestrictChatMember {
RestrictChatMember::new(chat_id, self.id, permissions)
}
pub fn promote_from(&self, chat_id: impl Into<ChatId>) -> PromoteChatMember {
PromoteChatMember::new(chat_id, self.id)
}
pub fn set_administrator_title_from(
&self,
chat_id: impl Into<ChatId>,
custom_title: impl Into<String>,
) -> SetChatAdministratorCustomTitle {
SetChatAdministratorCustomTitle::new(chat_id, self.id, custom_title)
}
pub fn approve_join_to(&self, chat_id: impl Into<ChatId>) -> ApproveChatJoinRequest {
ApproveChatJoinRequest::new(chat_id, self.id)
}
pub fn decline_join_to(&self, chat_id: impl Into<ChatId>) -> DeclineChatJoinRequest {
DeclineChatJoinRequest::new(chat_id, self.id)
}
pub fn get_member_from(&self, chat_id: impl Into<ChatId>) -> GetChatMember {
GetChatMember::new(chat_id, self.id)
}
}
#[derive(Debug, Deserialize)]
pub struct UserProfilePhotos {
pub total_count: usize,
pub photos: Vec<Vec<PhotoSize>>,
}
#[derive(Clone, Serialize)]
pub struct GetUserProfilePhotos {
user_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
offset: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<u32>,
}
impl GetUserProfilePhotos {
pub fn new(user_id: i64) -> Self {
Self {
user_id,
offset: None,
limit: None,
}
}
pub fn with_offset(self, offset: u32) -> Self {
Self {
offset: Some(offset),
..self
}
}
pub fn with_limit(self, limit: u32) -> Self {
Self {
limit: Some(limit),
..self
}
}
}
impl TelegramMethod for GetUserProfilePhotos {
type Response = UserProfilePhotos;
fn name() -> &'static str {
"getUserProfilePhotos"
}
}
impl JsonMethod for GetUserProfilePhotos {}