Skip to main content

twilight_http/request/channel/reaction/
delete_all_reactions.rs

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