twilight_http/request/channel/thread/
remove_thread_member.rs

1use crate::{
2    client::Client,
3    error::Error,
4    request::{Request, TryIntoRequest},
5    response::{marker::EmptyBody, Response, ResponseFuture},
6    routing::Route,
7};
8use std::future::IntoFuture;
9use twilight_model::id::{
10    marker::{ChannelMarker, UserMarker},
11    Id,
12};
13
14/// Remove another member from a thread.
15///
16/// Requires that the thread is not archived.
17///
18/// Requires the [`MANAGE_THREADS`] permission, unless both the thread is a
19/// [`PrivateThread`], and the current user is the creator of the thread.
20///
21/// [`PrivateThread`]: twilight_model::channel::ChannelType::PrivateThread
22/// [`MANAGE_THREADS`]: twilight_model::guild::Permissions::MANAGE_THREADS
23#[must_use = "requests must be configured and executed"]
24pub struct RemoveThreadMember<'a> {
25    channel_id: Id<ChannelMarker>,
26    http: &'a Client,
27    user_id: Id<UserMarker>,
28}
29
30impl<'a> RemoveThreadMember<'a> {
31    pub(crate) const fn new(
32        http: &'a Client,
33        channel_id: Id<ChannelMarker>,
34        user_id: Id<UserMarker>,
35    ) -> Self {
36        Self {
37            channel_id,
38            http,
39            user_id,
40        }
41    }
42}
43
44impl IntoFuture for RemoveThreadMember<'_> {
45    type Output = Result<Response<EmptyBody>, Error>;
46
47    type IntoFuture = ResponseFuture<EmptyBody>;
48
49    fn into_future(self) -> Self::IntoFuture {
50        let http = self.http;
51
52        match self.try_into_request() {
53            Ok(request) => http.request(request),
54            Err(source) => ResponseFuture::error(source),
55        }
56    }
57}
58
59impl TryIntoRequest for RemoveThreadMember<'_> {
60    fn try_into_request(self) -> Result<Request, Error> {
61        Ok(Request::from_route(&Route::RemoveThreadMember {
62            channel_id: self.channel_id.get(),
63            user_id: self.user_id.get(),
64        }))
65    }
66}