rustigram_api/methods/
reactions.rs1use crate::client::BotClient;
2use rustigram_types::message::ReactionType;
3use rustigram_types::user::ChatId;
4use serde::Serialize;
5use std::future::{Future, IntoFuture};
6use std::pin::Pin;
7
8#[derive(Serialize)]
9struct SetMessageReactionParams {
10 chat_id: ChatId,
11 message_id: i64,
12 #[serde(skip_serializing_if = "Option::is_none")]
13 reaction: Option<Vec<ReactionType>>,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 is_big: Option<bool>,
16}
17
18pub struct SetMessageReaction {
20 client: BotClient,
21 params: SetMessageReactionParams,
22}
23impl SetMessageReaction {
24 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, message_id: i64) -> Self {
25 Self {
26 client,
27 params: SetMessageReactionParams {
28 chat_id: chat_id.into(),
29 message_id,
30 reaction: None,
31 is_big: None,
32 },
33 }
34 }
35 pub fn reaction(mut self, r: Vec<ReactionType>) -> Self {
38 self.params.reaction = Some(r);
39 self
40 }
41 pub fn is_big(mut self, v: bool) -> Self {
43 self.params.is_big = Some(v);
44 self
45 }
46 pub fn emoji(self, emoji: impl Into<String>) -> Self {
48 self.reaction(vec![ReactionType::Emoji {
49 emoji: emoji.into(),
50 }])
51 }
52}
53impl IntoFuture for SetMessageReaction {
54 type Output = crate::error::Result<bool>;
55 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
56 fn into_future(self) -> Self::IntoFuture {
57 Box::pin(async move {
58 self.client
59 .post_json("setMessageReaction", &self.params)
60 .await
61 })
62 }
63}