Skip to content
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

Clen 1924: support for pagination params for push channels #123

Merged
merged 7 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions pubnub/lib/src/core/crypto/cipher_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ class CipherKey {
}

@override
bool operator ==(dynamic other) {
if (other == null) {
return false;
}
bool operator ==(Object other) {
if (runtimeType == other.runtimeType) {
return utf8.decode(data) == utf8.decode(other!.data);
return utf8.decode(data) == utf8.decode((other as CipherKey).data);
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion pubnub/lib/src/core/timetoken.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Timetoken implements Result {

/// Timetokens are compared based on their [value].
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
if (other is Timetoken) {
return value == other.value;
} else {
Expand Down
2 changes: 1 addition & 1 deletion pubnub/lib/src/core/user_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UserId {
String toString() => '$value';

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
if (other is UserId) {
return value == other.value;
}
Expand Down
2 changes: 1 addition & 1 deletion pubnub/lib/src/core/uuid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UUID {
String toString() => '$value';

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
if (other is UUID) {
return value == other.value;
}
Expand Down
8 changes: 6 additions & 2 deletions pubnub/lib/src/dx/_endpoints/push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ class ListPushChannelsParams extends Parameters {
PushGateway pushGateway;
Environment? environment;
String? topic;
String? start;
int? count;

ListPushChannelsParams(this.keyset, this.deviceId, this.pushGateway,
{this.topic, this.environment});
{this.topic, this.environment, this.start, this.count});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, you can add a trailing comma , after this.count so your IDE should break the line


@override
Request toRequest() {
Expand All @@ -74,7 +76,9 @@ class ListPushChannelsParams extends Parameters {
var queryParameters = {
if (keyset.authKey != null) 'auth': '${keyset.authKey}',
'uuid': '${keyset.uuid}',
'type': pushGateway.value()
'type': pushGateway.value(),
if (start != null && start!.isNotEmpty) 'start': start!,
if (count != null) 'count': '$count'
};
if (pushGateway == PushGateway.apns2) {
queryParameters['environment'] =
Expand Down
6 changes: 5 additions & 1 deletion pubnub/lib/src/dx/push/push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ mixin PushNotificationDx on Core {
/// If [gateway] is [PushGateway.apns2] then [topic] is mandatory to provide.
/// [topic] is bundle id of the mobile application.
/// [environment] denoting the environment of the mobile application for [PushGateway.apns2], it can be either:
/// [start] Starting channel for pagination. Use the last channel from the previous page request.
/// [count] Number of channels to return for pagination. Max of 1000 tokens at a time. Defaults to 500.
/// * [Environment.development] (which is the default value).
/// * [Environment.production].
Future<ListPushChannelsResult> listPushChannels(
String deviceId, PushGateway gateway,
{String? topic,
Environment? environment,
String? start,
int? count,
Keyset? keyset,
String? using}) async {
keyset ??= keysets[using];
Expand All @@ -33,7 +37,7 @@ mixin PushNotificationDx on Core {
if (gateway == PushGateway.apns2) Ensure(topic).isNotNull('topic');

var params = ListPushChannelsParams(keyset, deviceId, gateway,
topic: topic, environment: environment);
topic: topic, environment: environment, start: start, count: count);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same nitpick here, you can add a trailing comma , after count so your IDE should break the line

return defaultFlow<ListPushChannelsParams, ListPushChannelsResult>(
keyset: keyset,
core: this,
Expand Down
27 changes: 27 additions & 0 deletions pubnub/test/unit/dx/push_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,33 @@ void main() {
#environment: null
}));
});

test('listPushChannels delegate supported arguments', () async {
fakePubnub.returnWhen(
#listPushChannels,
Future.value(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use trailing commas here, I leave it up to you

ListPushChannelsResult.fromJson(['ch1', 'ch2', 'ch3'])));

await fakePubnub.listPushChannels('A332C23D', PushGateway.mpns,
start: 'ch2', count: 10);

var invocation = fakePubnub.invocations[0];

expect(invocation.isMethod, equals(true));
expect(invocation.memberName, equals(#listPushChannels));
expect(invocation.positionalArguments,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use trailing commas here, I leave it up to you

equals(['A332C23D', PushGateway.mpns]));
expect(
invocation.namedArguments,
equals({
#keyset: null,
#using: null,
#topic: null,
#environment: null,
#start: 'ch2',
#count: 10
}));
});
});
});
}
Loading