use rustigram_types::keyboard::PreparedKeyboardButton;
use crate::client::BotClient;
use crate::error::Result;
use rustigram_types::keyboard::KeyboardButton;
use serde::Serialize;
use std::future::{Future, IntoFuture};
use std::pin::Pin;
macro_rules! impl_into_future {
($builder:ident, $return_ty:ty, $method:literal) => {
impl IntoFuture for $builder {
type Output = Result<$return_ty>;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(async move { self.client.post_json($method, &self.params).await })
}
}
};
}
#[derive(Serialize)]
struct SavePreparedKeyboardButtonParams {
user_id: i64,
button: KeyboardButton,
}
pub struct SavePreparedKeyboardButton {
client: BotClient,
params: SavePreparedKeyboardButtonParams,
}
impl SavePreparedKeyboardButton {
pub(crate) fn new(client: BotClient, user_id: i64, button: KeyboardButton) -> Self {
Self {
client,
params: SavePreparedKeyboardButtonParams { user_id, button },
}
}
}
impl_into_future!(
SavePreparedKeyboardButton,
PreparedKeyboardButton,
"savePreparedKeyboardButton"
);
#[derive(Serialize)]
struct SetUserEmojiStatusParams {
user_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
emoji_status_custom_emoji_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
emoji_status_expiration_date: Option<i64>,
}
pub struct SetUserEmojiStatus {
client: BotClient,
params: SetUserEmojiStatusParams,
}
impl SetUserEmojiStatus {
pub(crate) fn new(client: BotClient, user_id: i64) -> Self {
Self {
client,
params: SetUserEmojiStatusParams {
user_id,
emoji_status_custom_emoji_id: None,
emoji_status_expiration_date: None,
},
}
}
pub fn emoji_status_custom_emoji_id(mut self, id: impl Into<String>) -> Self {
self.params.emoji_status_custom_emoji_id = Some(id.into());
self
}
pub fn emoji_status_expiration_date(mut self, ts: i64) -> Self {
self.params.emoji_status_expiration_date = Some(ts);
self
}
}
impl_into_future!(SetUserEmojiStatus, bool, "setUserEmojiStatus");