telegram_bot_async_raw/requests/
unban_chat_member.rs

1use crate::{requests::*, types::*};
2
3/// Use this method to unban a previously kicked user in a supergroup or channel.
4/// The user will not return to the group or channel automatically, but will be able to
5/// join via link, etc. The bot must be an administrator in the group for this to work.
6#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
7#[must_use = "requests do nothing unless sent"]
8pub struct UnbanChatMember {
9    chat_id: ChatRef,
10    user_id: UserId,
11}
12
13impl Request for UnbanChatMember {
14    type Type = JsonRequestType<Self>;
15    type Response = JsonTrueToUnitResponse;
16
17    fn serialize(&self) -> Result<HttpRequest, Error> {
18        Self::Type::serialize(RequestUrl::method("unbanChatMember"), self)
19    }
20}
21
22impl UnbanChatMember {
23    pub fn new<C, U>(chat: C, user: U) -> Self
24    where
25        C: ToChatRef,
26        U: ToUserId,
27    {
28        UnbanChatMember {
29            chat_id: chat.to_chat_ref(),
30            user_id: user.to_user_id(),
31        }
32    }
33}
34
35/// Unban a previously kicked user in a supergroup or channel.
36pub trait CanUnbanChatMemberForChat {
37    fn unban<O>(&self, other: O) -> UnbanChatMember
38    where
39        O: ToUserId;
40}
41
42impl<C> CanUnbanChatMemberForChat for C
43where
44    C: ToChatRef,
45{
46    fn unban<O>(&self, other: O) -> UnbanChatMember
47    where
48        O: ToUserId,
49    {
50        UnbanChatMember::new(self, other)
51    }
52}
53
54/// Unban a previously kicked user in a supergroup or channel.
55pub trait CanUnbanChatMemberForUser {
56    fn unban_in<O>(&self, other: O) -> UnbanChatMember
57    where
58        O: ToChatRef;
59}
60
61impl<U> CanUnbanChatMemberForUser for U
62where
63    U: ToUserId,
64{
65    fn unban_in<O>(&self, other: O) -> UnbanChatMember
66    where
67        O: ToChatRef,
68    {
69        UnbanChatMember::new(other, self)
70    }
71}