Skip to content

Commit

Permalink
Add endpoint pagination for reactions (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
abitofevrything authored Apr 14, 2024
1 parent e482f44 commit e9793e5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
19 changes: 19 additions & 0 deletions lib/src/extensions/managers/message_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,23 @@ extension MessageManagerExtensions on MessageManager {
pageSize: pageSize,
order: order,
);

/// Same as [fetchReactions], but has no limit on the number of reactions returned.
///
/// {@macro paginated_endpoint_streaming_parameters}
Stream<User> streamReactions(
Snowflake id,
ReactionBuilder emoji, {
Snowflake? after,
Snowflake? before,
int? pageSize,
}) =>
streamPaginatedEndpoint(
({before, after, limit}) => fetchReactions(id, emoji, after: after, limit: limit),
extractId: (user) => user.id,
before: before,
after: after,
pageSize: pageSize,
order: StreamOrder.oldestFirst,
);
}
13 changes: 12 additions & 1 deletion lib/src/extensions/message.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:nyxx/nyxx.dart';
import 'package:nyxx_extensions/src/extensions/channel.dart';
import 'package:nyxx_extensions/nyxx_extensions.dart';

/// Extensions on [Message]s.
extension MessageExtensions on Message {
Expand All @@ -25,4 +25,15 @@ extension MessageExtensions on Message {

return channel.sendMessage(copiedBuilder);
}

/// Same as [fetchReactions], but has no limit on the number of reactions returned.
///
/// {@macro paginated_endpoint_streaming_parameters}
Stream<User> streamReactions(
ReactionBuilder emoji, {
Snowflake? after,
Snowflake? before,
int? pageSize,
}) =>
manager.streamReactions(id, emoji, after: after, before: before, pageSize: pageSize);
}
2 changes: 1 addition & 1 deletion lib/src/utils/formatters.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:nyxx/src/models/snowflake.dart';
import 'package:nyxx/nyxx.dart';

/// Wraps the [code] in a code block with the specified language, if any.
String codeBlock(String code, [String language = '']) => '```$language\n$code\n```';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:

dependencies:
http: ^1.1.0
nyxx: ^6.0.0
nyxx: ^6.2.0

dev_dependencies:
coverage: ^1.0.3
Expand Down

0 comments on commit e9793e5

Please sign in to comment.