use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use serde::Serialize;
use crate::{
api::API,
entities::{message_id::MessageId, misc::chat_id::ChatId},
errors::ConogramError,
impl_into_future,
request::RequestT,
utils::deserialize_utils::is_false,
};
#[derive(Debug, Clone, Serialize)]
pub struct ForwardMessagesParams {
pub chat_id: ChatId,
#[serde(skip_serializing_if = "Option::is_none")]
pub message_thread_id: Option<i64>,
pub from_chat_id: ChatId,
pub message_ids: Vec<i64>,
#[serde(default, skip_serializing_if = "is_false")]
pub disable_notification: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub protect_content: bool,
}
impl_into_future!(ForwardMessagesRequest<'a>);
#[derive(Clone)]
pub struct ForwardMessagesRequest<'a> {
api: &'a API,
params: ForwardMessagesParams,
}
impl<'a> RequestT for ForwardMessagesRequest<'a> {
type ParamsType = ForwardMessagesParams;
type ReturnType = Vec<MessageId>;
fn get_name() -> &'static str {
"forwardMessages"
}
fn get_api_ref(&self) -> &API {
self.api
}
fn get_params_ref(&self) -> &Self::ParamsType {
&self.params
}
fn is_multipart() -> bool {
false
}
}
impl<'a> ForwardMessagesRequest<'a> {
pub fn new(
api: &'a API,
chat_id: impl Into<ChatId>,
from_chat_id: impl Into<ChatId>,
message_ids: impl IntoIterator<Item = impl Into<i64>>,
) -> Self {
Self {
api,
params: ForwardMessagesParams {
chat_id: chat_id.into(),
from_chat_id: from_chat_id.into(),
message_ids: message_ids.into_iter().map(Into::into).collect(),
message_thread_id: Option::default(),
disable_notification: bool::default(),
protect_content: bool::default(),
},
}
}
#[must_use]
pub fn chat_id(mut self, chat_id: impl Into<ChatId>) -> Self {
self.params.chat_id = chat_id.into();
self
}
#[must_use]
pub fn message_thread_id(mut self, message_thread_id: impl Into<i64>) -> Self {
self.params.message_thread_id = Some(message_thread_id.into());
self
}
#[must_use]
pub fn from_chat_id(mut self, from_chat_id: impl Into<ChatId>) -> Self {
self.params.from_chat_id = from_chat_id.into();
self
}
#[must_use]
pub fn message_ids(mut self, message_ids: impl IntoIterator<Item = impl Into<i64>>) -> Self {
self.params.message_ids = message_ids.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub fn disable_notification(mut self, disable_notification: impl Into<bool>) -> Self {
self.params.disable_notification = disable_notification.into();
self
}
#[must_use]
pub fn protect_content(mut self, protect_content: impl Into<bool>) -> Self {
self.params.protect_content = protect_content.into();
self
}
}
impl API {
pub fn forward_messages(
&self,
chat_id: impl Into<ChatId>,
from_chat_id: impl Into<ChatId>,
message_ids: impl IntoIterator<Item = impl Into<i64>>,
) -> ForwardMessagesRequest {
ForwardMessagesRequest::new(self, chat_id, from_chat_id, message_ids)
}
}