Skip to main content

twilight_http/request/channel/reaction/
delete_all_reaction.rs

1use super::RequestReactionType;
2#[cfg(not(target_os = "wasi"))]
3use crate::response::{Response, ResponseFuture, marker::EmptyBody};
4use crate::{
5    client::Client,
6    error::Error,
7    request::{Request, TryIntoRequest},
8    routing::Route,
9};
10use std::future::IntoFuture;
11use twilight_model::id::{
12    Id,
13    marker::{ChannelMarker, MessageMarker},
14};
15
16/// Remove all reactions of a specified emoji from a message.
17#[must_use = "requests must be configured and executed"]
18pub struct DeleteAllReaction<'a> {
19    channel_id: Id<ChannelMarker>,
20    emoji: &'a RequestReactionType<'a>,
21    http: &'a Client,
22    message_id: Id<MessageMarker>,
23}
24
25impl<'a> DeleteAllReaction<'a> {
26    pub(crate) const fn new(
27        http: &'a Client,
28        channel_id: Id<ChannelMarker>,
29        message_id: Id<MessageMarker>,
30        emoji: &'a RequestReactionType<'a>,
31    ) -> Self {
32        Self {
33            channel_id,
34            emoji,
35            http,
36            message_id,
37        }
38    }
39}
40
41#[cfg(not(target_os = "wasi"))]
42impl IntoFuture for DeleteAllReaction<'_> {
43    type Output = Result<Response<EmptyBody>, Error>;
44
45    type IntoFuture = ResponseFuture<EmptyBody>;
46
47    fn into_future(self) -> Self::IntoFuture {
48        let http = self.http;
49
50        match self.try_into_request() {
51            Ok(request) => http.request(request),
52            Err(source) => ResponseFuture::error(source),
53        }
54    }
55}
56
57impl TryIntoRequest for DeleteAllReaction<'_> {
58    fn try_into_request(self) -> Result<Request, Error> {
59        Ok(Request::from_route(&Route::DeleteMessageSpecificReaction {
60            channel_id: self.channel_id.get(),
61            message_id: self.message_id.get(),
62            emoji: self.emoji,
63        }))
64    }
65}