conogram/methods/
set_message_reaction.rs1use std::{
2 future::{Future, IntoFuture},
3 pin::Pin,
4};
5
6use serde::Serialize;
7
8use crate::{
9 api::API,
10 entities::{misc::chat_id::ChatId, reaction_type::ReactionType},
11 errors::ConogramError,
12 impl_into_future,
13 request::RequestT,
14 utils::deserialize_utils::is_false,
15};
16
17#[derive(Debug, Clone, Serialize)]
18pub struct SetMessageReactionParams {
19 pub chat_id: ChatId,
20 pub message_id: i64,
21 #[serde(skip_serializing_if = "Vec::is_empty")]
22 pub reaction: Vec<ReactionType>,
23 #[serde(default, skip_serializing_if = "is_false")]
24 pub is_big: bool,
25}
26
27impl_into_future!(SetMessageReactionRequest<'a>);
28
29#[derive(Clone)]
31pub struct SetMessageReactionRequest<'a> {
32 api: &'a API,
33 params: SetMessageReactionParams,
34}
35
36impl<'a> RequestT for SetMessageReactionRequest<'a> {
37 type ParamsType = SetMessageReactionParams;
38 type ReturnType = bool;
39 fn get_name() -> &'static str {
40 "setMessageReaction"
41 }
42 fn get_api_ref(&self) -> &API {
43 self.api
44 }
45 fn get_params_ref(&self) -> &Self::ParamsType {
46 &self.params
47 }
48 fn is_multipart() -> bool {
49 false
50 }
51}
52impl<'a> SetMessageReactionRequest<'a> {
53 pub fn new(api: &'a API, chat_id: impl Into<ChatId>, message_id: impl Into<i64>) -> Self {
54 Self {
55 api,
56 params: SetMessageReactionParams {
57 chat_id: chat_id.into(),
58 message_id: message_id.into(),
59 reaction: Vec::default(),
60 is_big: bool::default(),
61 },
62 }
63 }
64
65 #[must_use]
67 pub fn chat_id(mut self, chat_id: impl Into<ChatId>) -> Self {
68 self.params.chat_id = chat_id.into();
69 self
70 }
71
72 #[must_use]
74 pub fn message_id(mut self, message_id: impl Into<i64>) -> Self {
75 self.params.message_id = message_id.into();
76 self
77 }
78
79 #[must_use]
81 pub fn reaction(mut self, reaction: impl IntoIterator<Item = impl Into<ReactionType>>) -> Self {
82 self.params.reaction = reaction.into_iter().map(Into::into).collect();
83 self
84 }
85
86 #[must_use]
88 pub fn is_big(mut self, is_big: impl Into<bool>) -> Self {
89 self.params.is_big = is_big.into();
90 self
91 }
92}
93
94impl API {
95 pub fn set_message_reaction(
97 &self,
98 chat_id: impl Into<ChatId>,
99 message_id: impl Into<i64>,
100 ) -> SetMessageReactionRequest {
101 SetMessageReactionRequest::new(self, chat_id, message_id)
102 }
103}
104
105