telegram_bot_async_raw/requests/
pin_chat_message.rs1use std::ops::Not;
2
3use crate::{requests::*, types::*};
4
5#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
10#[must_use = "requests do nothing unless sent"]
11pub struct PinChatMessage {
12 chat_id: ChatRef,
13 message_id: MessageId,
14 #[serde(skip_serializing_if = "Not::not")]
15 disable_notification: bool,
16}
17
18impl Request for PinChatMessage {
19 type Type = JsonRequestType<Self>;
20 type Response = JsonTrueToUnitResponse;
21
22 fn serialize(&self) -> Result<HttpRequest, Error> {
23 Self::Type::serialize(RequestUrl::method("pinChatMessage"), self)
24 }
25}
26
27impl PinChatMessage {
28 pub fn new<C, M>(chat: C, message: M) -> Self
29 where
30 C: ToChatRef,
31 M: ToMessageId,
32 {
33 Self {
34 chat_id: chat.to_chat_ref(),
35 message_id: message.to_message_id(),
36 disable_notification: false,
37 }
38 }
39
40 pub fn disable_notification(mut self) -> Self {
41 self.disable_notification = true;
42 self
43 }
44}
45
46pub trait CanPinMessage {
47 fn pin(&self) -> PinChatMessage;
48}
49
50impl<M> CanPinMessage for M
51where
52 M: ToMessageId + ToSourceChat,
53{
54 fn pin(&self) -> PinChatMessage {
55 PinChatMessage::new(self.to_source_chat(), self.to_message_id())
56 }
57}