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}
64
65#[derive(Serialize)]
68struct DeleteMessageReactionParams {
69 chat_id: ChatId,
70 message_id: i64,
71 #[serde(skip_serializing_if = "Option::is_none")]
72 user_id: Option<i64>,
73 #[serde(skip_serializing_if = "Option::is_none")]
74 actor_chat_id: Option<i64>,
75}
76
77pub struct DeleteMessageReaction {
82 client: BotClient,
83 params: DeleteMessageReactionParams,
84}
85
86impl DeleteMessageReaction {
87 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, message_id: i64) -> Self {
88 Self {
89 client,
90 params: DeleteMessageReactionParams {
91 chat_id: chat_id.into(),
92 message_id,
93 user_id: None,
94 actor_chat_id: None,
95 },
96 }
97 }
98
99 pub fn user_id(mut self, id: i64) -> Self {
101 self.params.user_id = Some(id);
102 self
103 }
104
105 pub fn actor_chat_id(mut self, id: i64) -> Self {
107 self.params.actor_chat_id = Some(id);
108 self
109 }
110}
111
112impl IntoFuture for DeleteMessageReaction {
113 type Output = crate::error::Result<bool>;
114 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
115 fn into_future(self) -> Self::IntoFuture {
116 Box::pin(async move {
117 self.client
118 .post_json("deleteMessageReaction", &self.params)
119 .await
120 })
121 }
122}
123
124#[derive(Serialize)]
127struct DeleteAllMessageReactionsParams {
128 chat_id: ChatId,
129 #[serde(skip_serializing_if = "Option::is_none")]
130 user_id: Option<i64>,
131 #[serde(skip_serializing_if = "Option::is_none")]
132 actor_chat_id: Option<i64>,
133}
134
135pub struct DeleteAllMessageReactions {
140 client: BotClient,
141 params: DeleteAllMessageReactionsParams,
142}
143
144impl DeleteAllMessageReactions {
145 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
146 Self {
147 client,
148 params: DeleteAllMessageReactionsParams {
149 chat_id: chat_id.into(),
150 user_id: None,
151 actor_chat_id: None,
152 },
153 }
154 }
155
156 pub fn user_id(mut self, id: i64) -> Self {
158 self.params.user_id = Some(id);
159 self
160 }
161
162 pub fn actor_chat_id(mut self, id: i64) -> Self {
164 self.params.actor_chat_id = Some(id);
165 self
166 }
167}
168
169impl IntoFuture for DeleteAllMessageReactions {
170 type Output = crate::error::Result<bool>;
171 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
172 fn into_future(self) -> Self::IntoFuture {
173 Box::pin(async move {
174 self.client
175 .post_json("deleteAllMessageReactions", &self.params)
176 .await
177 })
178 }
179}