twilight_http/request/channel/thread/
get_public_archived_threads.rs

1use crate::{
2    client::Client,
3    error::Error,
4    request::{Request, TryIntoRequest},
5    response::{Response, ResponseFuture},
6    routing::Route,
7};
8use std::future::IntoFuture;
9use twilight_model::{
10    channel::thread::ThreadsListing,
11    id::{marker::ChannelMarker, Id},
12};
13
14/// Returns archived public threads in the channel.
15///
16/// Requires the [`READ_MESSAGE_HISTORY`] permission.
17///
18/// Threads are ordered by [`archive_timestamp`] in descending order.
19///
20/// When called in a [`GuildText`] channel, returns [`PublicThread`]s.
21///
22/// When called in a [`GuildAnnouncement`] channel, returns [`AnnouncementThread`]s.
23///
24/// [`AnnouncementThread`]: twilight_model::channel::ChannelType::AnnouncementThread
25/// [`archive_timestamp`]: twilight_model::channel::thread::ThreadMetadata::archive_timestamp
26/// [`GuildAnnouncement`]: twilight_model::channel::ChannelType::GuildAnnouncement
27/// [`GuildText`]: twilight_model::channel::ChannelType::GuildText
28/// [`PublicThread`]: twilight_model::channel::ChannelType::PublicThread
29/// [`READ_MESSAGE_HISTORY`]: twilight_model::guild::Permissions::READ_MESSAGE_HISTORY
30#[must_use = "requests must be configured and executed"]
31pub struct GetPublicArchivedThreads<'a> {
32    before: Option<&'a str>,
33    channel_id: Id<ChannelMarker>,
34    http: &'a Client,
35    limit: Option<u64>,
36}
37
38impl<'a> GetPublicArchivedThreads<'a> {
39    pub(crate) const fn new(http: &'a Client, channel_id: Id<ChannelMarker>) -> Self {
40        Self {
41            before: None,
42            channel_id,
43            http,
44            limit: None,
45        }
46    }
47
48    /// Return threads before this ISO 8601 timestamp.
49    pub const fn before(mut self, before: &'a str) -> Self {
50        self.before = Some(before);
51
52        self
53    }
54
55    /// Maximum number of threads to return.
56    pub const fn limit(mut self, limit: u64) -> Self {
57        self.limit = Some(limit);
58
59        self
60    }
61}
62
63impl IntoFuture for GetPublicArchivedThreads<'_> {
64    type Output = Result<Response<ThreadsListing>, Error>;
65
66    type IntoFuture = ResponseFuture<ThreadsListing>;
67
68    fn into_future(self) -> Self::IntoFuture {
69        let http = self.http;
70
71        match self.try_into_request() {
72            Ok(request) => http.request(request),
73            Err(source) => ResponseFuture::error(source),
74        }
75    }
76}
77
78impl TryIntoRequest for GetPublicArchivedThreads<'_> {
79    fn try_into_request(self) -> Result<Request, Error> {
80        Ok(Request::from_route(&Route::GetPublicArchivedThreads {
81            before: self.before,
82            channel_id: self.channel_id.get(),
83            limit: self.limit,
84        }))
85    }
86}