Skip to main content

twilight_http/request/guild/
get_active_threads.rs

1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture};
3use crate::{
4    client::Client,
5    error::Error,
6    request::{Request, TryIntoRequest},
7    routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::{
11    channel::thread::ThreadsListing,
12    id::{Id, marker::GuildMarker},
13};
14
15/// Returns all active threads in the guild.
16///
17/// Includes public and private threads. Threads are ordered by their ID in
18/// descending order.
19#[must_use = "requests must be configured and executed"]
20pub struct GetActiveThreads<'a> {
21    guild_id: Id<GuildMarker>,
22    http: &'a Client,
23}
24
25impl<'a> GetActiveThreads<'a> {
26    pub(crate) const fn new(http: &'a Client, guild_id: Id<GuildMarker>) -> Self {
27        Self { guild_id, http }
28    }
29}
30
31#[cfg(not(target_os = "wasi"))]
32impl IntoFuture for GetActiveThreads<'_> {
33    type Output = Result<Response<ThreadsListing>, Error>;
34
35    type IntoFuture = ResponseFuture<ThreadsListing>;
36
37    fn into_future(self) -> Self::IntoFuture {
38        let http = self.http;
39
40        match self.try_into_request() {
41            Ok(request) => http.request(request),
42            Err(source) => ResponseFuture::error(source),
43        }
44    }
45}
46
47impl TryIntoRequest for GetActiveThreads<'_> {
48    fn try_into_request(self) -> Result<Request, Error> {
49        Ok(Request::from_route(&Route::GetActiveThreads {
50            guild_id: self.guild_id.get(),
51        }))
52    }
53}