Skip to content

Commit

Permalink
Support creating standalone public threads (#2470)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenhl authored Jul 6, 2023
1 parent 77b9e33 commit 768b952
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
9 changes: 5 additions & 4 deletions src/builder/create_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ impl<'a> CreateThread<'a> {

/// The thread type, either [`ChannelType::PublicThread`] or [`ChannelType::PrivateThread`].
///
/// **Note**: This defaults to [`ChannelType::PrivateThread`] in order to match the behavior
/// when thread documentation was first published. This is a bit of a weird default though, and
/// **Note**: This field is ignored for message threads, and defaults to
/// [`ChannelType::PrivateThread`] for standalone threads in order to match the behavior when
/// thread documentation was first published. This is a bit of a weird default though, and
/// thus is highly likely to change in the future, so it is recommended to always explicitly
/// setting it to avoid any breaking change.
pub fn kind(mut self, kind: ChannelType) -> Self {
Expand Down Expand Up @@ -112,8 +113,8 @@ impl<'a> Builder for CreateThread<'a> {
) -> Result<GuildChannel> {
let http = cache_http.http();
match ctx.1 {
Some(id) => http.create_public_thread(ctx.0, id, &self, self.audit_log_reason).await,
None => http.create_private_thread(ctx.0, &self, self.audit_log_reason).await,
Some(id) => http.create_thread_from_message(ctx.0, id, &self, self.audit_log_reason).await,
None => http.create_thread(ctx.0, &self, self.audit_log_reason).await,
}
}
}
13 changes: 6 additions & 7 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,8 @@ impl Http {
.await
}

/// Creates a public thread channel in the [`GuildChannel`] given its Id, with a base message
/// Id.
pub async fn create_public_thread(
/// Creates a thread channel in the [`GuildChannel`] given its Id, with a base message Id.
pub async fn create_thread_from_message(
&self,
channel_id: ChannelId,
message_id: MessageId,
Expand All @@ -384,7 +383,7 @@ impl Http {
multipart: None,
headers: audit_log_reason.map(reason_into_header),
method: LightMethod::Post,
route: Route::ChannelPublicThreads {
route: Route::ChannelMessageThreads {
channel_id,
message_id,
},
Expand All @@ -393,8 +392,8 @@ impl Http {
.await
}

/// Creates a private thread channel in the [`GuildChannel`] given its Id.
pub async fn create_private_thread(
/// Creates a thread channel not attached to a message in the [`GuildChannel`] given its Id.
pub async fn create_thread(
&self,
channel_id: ChannelId,
map: &impl serde::Serialize,
Expand All @@ -407,7 +406,7 @@ impl Http {
multipart: None,
headers: audit_log_reason.map(reason_into_header),
method: LightMethod::Post,
route: Route::ChannelPrivateThreads {
route: Route::ChannelThreads {
channel_id,
},
params: None,
Expand Down
4 changes: 2 additions & 2 deletions src/http/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ routes! ('a, {
api!("/channels/{}/webhooks", channel_id),
Some(RatelimitingKind::PathAndId(channel_id.0));

ChannelPublicThreads { channel_id: ChannelId, message_id: MessageId },
ChannelMessageThreads { channel_id: ChannelId, message_id: MessageId },
api!("/channels/{}/messages/{}/threads", channel_id, message_id),
Some(RatelimitingKind::PathAndId(channel_id.0));

ChannelPrivateThreads { channel_id: ChannelId },
ChannelThreads { channel_id: ChannelId },
api!("/channels/{}/threads", channel_id),
Some(RatelimitingKind::PathAndId(channel_id.0));

Expand Down
12 changes: 6 additions & 6 deletions src/model/channel/channel_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,8 @@ impl ChannelId {
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
#[doc(alias = "create_thread")]
pub async fn create_public_thread(
#[doc(alias = "create_public_thread")]
pub async fn create_thread_from_message(
self,
cache_http: impl CacheHttp,
message_id: impl Into<MessageId>,
Expand All @@ -917,18 +917,18 @@ impl ChannelId {
builder.execute(cache_http, (self, Some(message_id.into()))).await
}

/// Creates a private thread.
/// Creates a thread that is not connected to a message.
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
#[doc(alias = "create_thread")]
pub async fn create_private_thread(
#[doc(alias = "create_public_thread", alias = "create_private_thread")]
pub async fn create_thread(
self,
cache_http: impl CacheHttp,
builder: CreateThread<'_>,
) -> Result<GuildChannel> {
builder.kind(ChannelType::PrivateThread).execute(cache_http, (self, None)).await
builder.execute(cache_http, (self, None)).await
}

/// Creates a post in a forum channel.
Expand Down
10 changes: 5 additions & 5 deletions src/model/channel/guild_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,26 +1172,26 @@ impl GuildChannel {
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
pub async fn create_public_thread(
pub async fn create_thread_from_message(
&self,
cache_http: impl CacheHttp,
message_id: impl Into<MessageId>,
builder: CreateThread<'_>,
) -> Result<GuildChannel> {
self.id.create_public_thread(cache_http, message_id, builder).await
self.id.create_thread_from_message(cache_http, message_id, builder).await
}

/// Creates a private thread.
/// Creates a thread that is not connected to a message.
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
pub async fn create_private_thread(
pub async fn create_thread(
&self,
cache_http: impl CacheHttp,
builder: CreateThread<'_>,
) -> Result<GuildChannel> {
self.id.create_private_thread(cache_http, builder).await
self.id.create_thread(cache_http, builder).await
}

/// Creates a post in a forum channel.
Expand Down

0 comments on commit 768b952

Please sign in to comment.