use super::call_method;
#[allow(deprecated)]
use crate::{
connectors::Client,
errors, token,
types::{
message,
parameters::{ChatId, ImplicitChatId, NotificationState},
},
};
use serde::Serialize;
#[derive(Serialize, Debug, Clone)]
#[must_use = "methods do nothing unless turned into a future"]
pub struct PinChatMessage<'a> {
#[serde(skip)]
client: &'a Client,
#[serde(skip)]
token: token::Ref<'a>,
chat_id: ChatId<'a>,
message_id: message::Id,
#[serde(skip_serializing_if = "Option::is_none")]
disable_notification: Option<bool>,
}
impl<'a> PinChatMessage<'a> {
pub(crate) fn new(
client: &'a Client,
token: token::Ref<'a>,
chat_id: impl ImplicitChatId<'a>,
message_id: message::Id,
) -> Self {
Self {
client,
token,
chat_id: chat_id.into(),
message_id,
disable_notification: None,
}
}
pub fn is_notification_disabled(mut self, is_disabled: bool) -> Self {
self.disable_notification = Some(is_disabled);
self
}
#[doc(hidden)]
#[deprecated(
since = "0.6.6",
note = "use `is_notification_disabled` which takes a `bool`"
)]
#[allow(deprecated)]
pub fn notification(self, state: NotificationState) -> Self {
self.is_notification_disabled(state.is_disabled())
}
}
impl PinChatMessage<'_> {
pub async fn call(self) -> Result<(), errors::MethodCall> {
call_method::<bool>(
self.client,
self.token,
"pinChatMessage",
None,
serde_json::to_vec(&self).unwrap(),
)
.await?;
Ok(())
}
}