Skip to content

Paginated pinned messages #1366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jul 5, 2025
Merged

Paginated pinned messages #1366

merged 25 commits into from
Jul 5, 2025

Conversation

valzargaming
Copy link
Member

@valzargaming valzargaming commented Jul 5, 2025

https://discord.com/developers/docs/change-log#paginated-pin-endpoints

This pull request introduces significant updates to the handling of pinned messages in both Channel and Thread classes, aligning with Discord's updated API endpoints and adding new functionality for pagination and improved type handling. The changes also include the addition of two new classes, MessagePin and MessagePinData, to encapsulate pinned message data. Below is a categorized summary of the most important changes:

API Endpoint Updates and Pagination Support

  • Updated getPinnedMessages in Channel and Thread to use the new CHANNEL_MESSAGES_PINS endpoint, with added support for pagination via limit and before options. This includes validation for permissions like view_channel and read_message_history. ([[1]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-347cb634bd9dfce6baf790e117c398ae2c78812c67bfbbce182b3a32b4e1313fL301-R351), [[2]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-d8ef6d2acb3e5337f4b975c64a55437b1bc76c2f8312a8dd0912cf9e031594d5L478-R533))
  • Updated pinMessage and unpinMessage methods in Channel and Thread to use the new CHANNEL_MESSAGES_PIN endpoint for pinning and unpinning messages. ([[1]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-347cb634bd9dfce6baf790e117c398ae2c78812c67bfbbce182b3a32b4e1313fL962-R1000), [[2]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-347cb634bd9dfce6baf790e117c398ae2c78812c67bfbbce182b3a32b4e1313fL1003-R1043), [[3]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-d8ef6d2acb3e5337f4b975c64a55437b1bc76c2f8312a8dd0912cf9e031594d5L650-R686), [[4]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-d8ef6d2acb3e5337f4b975c64a55437b1bc76c2f8312a8dd0912cf9e031594d5L686-R722))

New Classes for Pinned Message Data

  • Added MessagePin class to represent individual pinned messages with their pinned_at timestamp and corresponding Message object. ([src/Discord/Parts/Channel/Message/MessagePin.phpR1-R49](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-db162fcf07afe760466cdb97e45a3b766b5a4c2fde90c0a7ca0a4e9f483bbba0R1-R49))
  • Added MessagePinData class to represent a collection of pinned messages and a has_more flag for pagination. ([src/Discord/Parts/Channel/Message/MessagePinData.phpR1-R51](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-2d9d8f7c548f3dd3df122292456eace6272f85ab03aa5e1cc72bbff780976b45R1-R51))

Documentation and Code Consistency

  • Updated method docblocks in Channel and Thread to reflect the new endpoints and the addition of pagination options. ([[1]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-347cb634bd9dfce6baf790e117c398ae2c78812c67bfbbce182b3a32b4e1313fL301-R351), [[2]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-d8ef6d2acb3e5337f4b975c64a55437b1bc76c2f8312a8dd0912cf9e031594d5L478-R533))
  • Updated links in docblocks to point to the new Discord API documentation for pinning and unpinning messages. ([[1]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-347cb634bd9dfce6baf790e117c398ae2c78812c67bfbbce182b3a32b4e1313fL931-R977), [[2]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-347cb634bd9dfce6baf790e117c398ae2c78812c67bfbbce182b3a32b4e1313fL972-R1010), [[3]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-d8ef6d2acb3e5337f4b975c64a55437b1bc76c2f8312a8dd0912cf9e031594d5L478-R533))

Miscellaneous

  • Added MessagePinData to imports in Channel and Thread classes to support the new functionality. ([[1]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-347cb634bd9dfce6baf790e117c398ae2c78812c67bfbbce182b3a32b4e1313fR39), [[2]](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-d8ef6d2acb3e5337f4b975c64a55437b1bc76c2f8312a8dd0912cf9e031594d5R24))
  • Introduced the resolve function in Thread to handle cases where no pinned messages are returned due to missing permissions. ([src/Discord/Parts/Thread/Thread.phpR44](https://github.com/discord-php/DiscordPHP/pull/1366/files#diff-d8ef6d2acb3e5337f4b975c64a55437b1bc76c2f8312a8dd0912cf9e031594d5R44))

@valzargaming valzargaming changed the title Paginated pins Paginated pinned messages Jul 5, 2025
@valzargaming
Copy link
Member Author

[2025-07-05T11:48:01.744241+00:00] Civ13.WARNING: REQ GET channels/562715700360380434/messages/pins failed: An error occurred in the underlying stream  
[2025-07-05T11:48:01.744359+00:00] Civ13.DEBUG: http not checking queue {"waiting":0,"empty":true}
[2025-07-05T11:48:01.744440+00:00] Civ13.WARNING: Unhandled Promise Rejection: An error occurred in the underlying stream [D:\GitHub\Civilizationbot\vendor\react\http\src\Io\ClientRequestStream.php:246] \n#0 D:\GitHub\Civilizationbot\vendor\evenement\evenement\src\EventEmitterTrait.php(143): React\Http\Io\ClientRequestStream->handleError(Object(RuntimeException))
\n#1 D:\GitHub\Civilizationbot\vendor\react\stream\src\Util.php(71): Evenement\EventEmitter->emit('error', Array)
\n#2 D:\GitHub\Civilizationbot\vendor\evenement\evenement\src\EventEmitterTrait.php(143): React\Stream\Util::{closure:React\Stream\Util::forwardEvents():70}(Object(RuntimeException))
\n#3 D:\GitHub\Civilizationbot\vendor\react\stream\src\DuplexResourceStream.php(203): Evenement\EventEmitter->emit('error', Array)
\n#4 D:\GitHub\Civilizationbot\vendor\react\event-loop\src\StreamSelectLoop.php(246): React\Stream\DuplexResourceStream->handleData(Resource id \n#427)
\n#5 D:\GitHub\Civilizationbot\vendor\react\event-loop\src\StreamSelectLoop.php(213): React\EventLoop\StreamSelectLoop->waitForStreamActivity(5000000)
\n#6 D:\GitHub\Civilizationbot\vendor\react\event-loop\src\Loop.php(55): React\EventLoop\StreamSelectLoop->run()
\n#7 [internal function]: React\EventLoop\Loop::{closure:React\EventLoop\Loop::get():47}()
\n#8 {main}

@valzargaming
Copy link
Member Author

Tested and confirmed working.

@valzargaming valzargaming merged commit c8352c3 into master Jul 5, 2025
1 of 2 checks passed
@valzargaming valzargaming deleted the channel-messages-pins branch July 5, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant