Skip to content

Commit 95e3508

Browse files
committed
1 parent b949903 commit 95e3508

File tree

5 files changed

+65
-17
lines changed

5 files changed

+65
-17
lines changed

src/http/client.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,7 +3924,25 @@ impl Http {
39243924
}
39253925

39263926
/// Gets all pins of a channel.
3927-
pub async fn get_pins(&self, channel_id: GenericChannelId) -> Result<Vec<Message>> {
3927+
pub async fn get_pins(
3928+
&self,
3929+
channel_id: GenericChannelId,
3930+
before: Option<Timestamp>,
3931+
limit: Option<u8>,
3932+
) -> Result<MessagePinsPage> {
3933+
let (before_str, limit_str);
3934+
let mut params = ArrayVec::<_, 2>::new();
3935+
3936+
if let Some(before) = before {
3937+
before_str = before.to_string();
3938+
params.push(("before", before_str.as_str()));
3939+
}
3940+
3941+
if let Some(limit) = limit {
3942+
limit_str = limit.to_arraystring();
3943+
params.push(("limit", limit_str.as_str()));
3944+
}
3945+
39283946
self.fire(Request {
39293947
body: None,
39303948
multipart: None,
@@ -3933,7 +3951,7 @@ impl Http {
39333951
route: Route::ChannelPins {
39343952
channel_id,
39353953
},
3936-
params: None,
3954+
params: Some(&params),
39373955
})
39383956
.await
39393957
}

src/http/routing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ routes! ('a, {
138138
Some(RatelimitingKind::PathAndId(GenericId::new(channel_id.get())));
139139

140140
ChannelPin { channel_id: GenericChannelId, message_id: MessageId },
141-
api!("/channels/{}/pins/{}", channel_id, message_id),
141+
api!("/channels/{}/messages/pins/{}", channel_id, message_id),
142142
Some(RatelimitingKind::PathAndId(GenericId::new(channel_id.get())));
143143

144144
ChannelPins { channel_id: GenericChannelId },
145-
api!("/channels/{}/pins", channel_id),
145+
api!("/channels/{}/messages/pins", channel_id),
146146
Some(RatelimitingKind::PathAndId(GenericId::new(channel_id.get())));
147147

148148
ChannelTyping { channel_id: GenericChannelId },

src/model/channel/channel_id.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,14 +786,14 @@ impl GenericChannelId {
786786

787787
/// Pins a [`Message`] to the channel.
788788
///
789-
/// **Note**: Requires the [Manage Messages] permission.
789+
/// **Note**: Requires the [Pin Messages] permission.
790790
///
791791
/// # Errors
792792
///
793793
/// Returns [`Error::Http`] if the current user lacks permission, or if the channel has too
794794
/// many pinned messages.
795795
///
796-
/// [Manage Messages]: Permissions::MANAGE_MESSAGES
796+
/// [Pin Messages]: Permissions::PIN_MESSAGES
797797
pub async fn pin(self, http: &Http, message_id: MessageId, reason: Option<&str>) -> Result<()> {
798798
http.pin_message(self, message_id, reason).await
799799
}
@@ -811,15 +811,20 @@ impl GenericChannelId {
811811
/// Returns [`Error::Http`] if the current user lacks permission to view the channel.
812812
///
813813
/// [Read Message History]: Permissions::READ_MESSAGE_HISTORY
814-
pub async fn pins(self, cache_http: impl CacheHttp) -> Result<Vec<Message>> {
815-
let messages = cache_http.http().get_pins(self).await?;
814+
pub async fn pins(
815+
self,
816+
cache_http: impl CacheHttp,
817+
before: Option<Timestamp>,
818+
limit: Option<u8>,
819+
) -> Result<MessagePinsPage> {
820+
let page = cache_http.http().get_pins(self, before, limit).await?;
816821

817822
#[cfg(feature = "cache")]
818823
if let Some(cache) = cache_http.cache() {
819-
cache.fill_message_cache(self, messages.iter().cloned());
824+
cache.fill_message_cache(self, page.items.iter().map(|m| m.message.clone()));
820825
}
821826

822-
Ok(messages)
827+
Ok(page)
823828
}
824829

825830
/// Gets the list of [`User`]s who have reacted to a [`Message`] with a certain [`Emoji`].
@@ -1001,13 +1006,13 @@ impl GenericChannelId {
10011006

10021007
/// Unpins a [`Message`] in the channel given by its Id.
10031008
///
1004-
/// Requires the [Manage Messages] permission.
1009+
/// Requires the [Pin Messages] permission.
10051010
///
10061011
/// # Errors
10071012
///
10081013
/// Returns [`Error::Http`] if the current user lacks permission.
10091014
///
1010-
/// [Manage Messages]: Permissions::MANAGE_MESSAGES
1015+
/// [Pin Messages]: Permissions::PIN_MESSAGES
10111016
pub async fn unpin(
10121017
self,
10131018
http: &Http,

src/model/channel/message.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,13 @@ impl Message {
448448

449449
/// Pins this message to its channel.
450450
///
451-
/// **Note**: Requires the [Manage Messages] permission.
451+
/// **Note**: Requires the [Pin Messages] permission.
452452
///
453453
/// # Errors
454454
///
455455
/// Returns [`Error::Http`] if the current user lacks permission or if invalid data is given.
456456
///
457-
/// [Manage Messages]: Permissions::MANAGE_MESSAGES
457+
/// [Pin Messages]: Permissions::PIN_MESSAGES
458458
pub async fn pin(&self, http: &Http, reason: Option<&str>) -> Result<()> {
459459
self.channel_id.pin(http, self.id, reason).await
460460
}
@@ -546,13 +546,13 @@ impl Message {
546546

547547
/// Unpins the message from its channel.
548548
///
549-
/// **Note**: Requires the [Manage Messages] permission.
549+
/// **Note**: Requires the [Pin Messages] permission.
550550
///
551551
/// # Errors
552552
///
553553
/// Returns [`Error::Http`] if the current user lacks permission or if invalid data is given.
554554
///
555-
/// [Manage Messages]: Permissions::MANAGE_MESSAGES
555+
/// [Pin Messages]: Permissions::PIN_MESSAGES
556556
pub async fn unpin(&self, http: &Http, reason: Option<&str>) -> Result<()> {
557557
http.unpin_message(self.channel_id, self.id, reason).await
558558
}
@@ -1171,6 +1171,28 @@ pub struct PollAnswerCount {
11711171
pub me_voted: bool,
11721172
}
11731173

1174+
/// A pinned message returned as part of a paginated Get Channel Pins query.
1175+
///
1176+
/// [Discord docs](https://discord.com/developers/docs/resources/message#message-pin-object)
1177+
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1178+
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1179+
#[non_exhaustive]
1180+
pub struct MessagePin {
1181+
pub pinned_at: Timestamp,
1182+
pub message: Message,
1183+
}
1184+
1185+
/// The response data for a paginated Get Channel Pins query.
1186+
///
1187+
/// [Discord docs](https://discord.com/developers/docs/resources/message#get-channel-pins)
1188+
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1189+
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
1190+
#[non_exhaustive]
1191+
pub struct MessagePinsPage {
1192+
pub items: Vec<MessagePin>,
1193+
pub has_more: bool,
1194+
}
1195+
11741196
// all tests here require cache, move if non-cache test is added
11751197
#[cfg(all(test, feature = "cache"))]
11761198
mod tests {

src/model/permissions.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,9 @@ generate_permissions! {
403403
/// Allows attaching polls to message sends.
404404
SEND_POLLS, send_polls, "Send Polls" = 1 << 49;
405405
/// Allows user-installed apps to send public responses.
406-
USE_EXTERNAL_APPS, use_external_apps, "Use External Apps" = 1 << 50
406+
USE_EXTERNAL_APPS, use_external_apps, "Use External Apps" = 1 << 50;
407+
/// Allows pinning and unpinning messages.
408+
PIN_MESSAGES, pin_messages, "Pin Messages" = 1 << 51
407409
}
408410

409411
#[cfg(feature = "model")]
@@ -428,6 +430,7 @@ impl Permissions {
428430
| Self::SEND_VOICE_MESSAGES
429431
| Self::SEND_POLLS
430432
| Self::USE_EXTERNAL_APPS
433+
| Self::PIN_MESSAGES
431434
}
432435
}
433436

0 commit comments

Comments
 (0)