Skip to content

Commit

Permalink
Don't add controls to paginated messages multiple times (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
abitofevrything authored Nov 7, 2023
1 parent ffa5abf commit cb0a428
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/src/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ extension MessageUtils on Message {
/// Sends a reply to the message.
Future<Message> sendReply(MessageBuilder builder) {
final copiedBuilder = MessageBuilder(
allowedMentions: builder.allowedMentions,
attachments: builder.attachments,
components: builder.components,
content: builder.content,
embeds: builder.embeds,
nonce: builder.nonce,
replyId: id,
requireReplyToExist: builder.requireReplyToExist,
stickerIds: builder.stickerIds,
suppressEmbeds: builder.suppressEmbeds,
suppressNotifications: builder.suppressNotifications,
tts: builder.tts,
allowedMentions: builder.allowedMentions,
attachments: builder.attachments,
components: builder.components,
content: builder.content,
embeds: builder.embeds,
nonce: builder.nonce,
replyId: id,
requireReplyToExist: builder.requireReplyToExist,
stickerIds: builder.stickerIds,
suppressEmbeds: builder.suppressEmbeds,
suppressNotifications: builder.suppressNotifications,
tts: builder.tts,
);

return channel.sendMessage(copiedBuilder);
Expand Down
6 changes: 6 additions & 0 deletions lib/src/pagination.dart
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ class _PaginationState {
throw NyxxException('Cannot add pagination controls to builder: too many component rows');
}

final knownIds = {jumpToStartId, jumpToEndId, previousId, nextId};
if (builder.components?.any((row) => row.components.any((element) => element is ButtonBuilder && knownIds.contains(element.customId))) == true) {
// We've already added controls to this builder, likely when the user navigated to this page previously.
return;
}

final showJumpToEnds = options?.showJumpToEnds ?? pagination.options.showJumpToEnds ?? true;
final showPageIndex = options?.showPageIndex ?? pagination.options.showPageIndex ?? true;

Expand Down

0 comments on commit cb0a428

Please sign in to comment.