Skip to content

Commit

Permalink
Clen 1924: support for pagination params for push channels (#123)
Browse files Browse the repository at this point in the history
* added support for pagination params for listPushChannels

* fix == oprator implementation for CipherKey

* fix equal operator. take -2

* fix warnings for equal operator

* formatting

* PubNub SDK v4.3.3 release.

* Update .pubnub.yml

Co-authored-by: Karolina Rymer <[email protected]>

---------

Co-authored-by: PubNub Release Bot <[email protected]>
Co-authored-by: Karolina Rymer <[email protected]>
  • Loading branch information
3 people authored Mar 28, 2024
1 parent 2a5f47e commit 508ae72
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 19 deletions.
7 changes: 6 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
---
changelog:
- date: 2024-03-28
version: v4.3.3
changes:
- type: feature
text: "Added support for pagination params for listChannels API of push notification devices."
- date: 2024-01-22
version: v4.3.2
changes:
Expand Down Expand Up @@ -442,7 +447,7 @@ supported-platforms:
platforms:
- "Dart SDK >=2.6.0 <3.0.0"
version: "PubNub Dart SDK"
version: "4.3.2"
version: "4.3.3"
sdks:
-
full-name: PubNub Dart SDK
Expand Down
6 changes: 6 additions & 0 deletions pubnub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v4.3.3
March 28 2024

#### Added
- Added support for pagination params for listChannels api of push notification devices.

## v4.3.2
January 22 2024

Expand Down
2 changes: 1 addition & 1 deletion pubnub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To add the package to your Dart or Flutter project, add `pubnub` as a dependency

```yaml
dependencies:
pubnub: ^4.3.2
pubnub: ^4.3.3
```
After adding the dependency to `pubspec.yaml`, run the `dart pub get` command in the root directory of your project (the same that the `pubspec.yaml` is in).
Expand Down
2 changes: 1 addition & 1 deletion pubnub/lib/src/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Core {
/// Internal module responsible for supervising.
SupervisorModule supervisor = SupervisorModule();

static String version = '4.3.2';
static String version = '4.3.3';

Core(
{Keyset? defaultKeyset,
Expand Down
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
19 changes: 15 additions & 4 deletions pubnub/lib/src/dx/_endpoints/push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,18 @@ class ListPushChannelsParams extends Parameters {
PushGateway pushGateway;
Environment? environment;
String? topic;

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

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

@override
Request toRequest() {
Expand All @@ -74,7 +83,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
15 changes: 13 additions & 2 deletions pubnub/lib/src/dx/push/push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,32 @@ 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];

Ensure(deviceId).isNotEmpty('deviceId');
if (gateway == PushGateway.apns2) Ensure(topic).isNotNull('topic');

var params = ListPushChannelsParams(keyset, deviceId, gateway,
topic: topic, environment: environment);
var params = ListPushChannelsParams(
keyset,
deviceId,
gateway,
topic: topic,
environment: environment,
start: start,
count: count,
);
return defaultFlow<ListPushChannelsParams, ListPushChannelsResult>(
keyset: keyset,
core: this,
Expand Down
2 changes: 1 addition & 1 deletion pubnub/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pubnub
description: PubNub SDK v5 for Dart lang (with Flutter support) that allows you to create real-time applications
version: 4.3.2
version: 4.3.3
homepage: https://www.pubnub.com/docs/sdks/dart

environment:
Expand Down
31 changes: 31 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,37 @@ void main() {
#environment: null
}));
});

test('listPushChannels delegate supported arguments', () async {
fakePubnub.returnWhen(
#listPushChannels,
Future.value(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,
equals(['A332C23D', PushGateway.mpns]));
expect(
invocation.namedArguments,
equals({
#keyset: null,
#using: null,
#topic: null,
#environment: null,
#start: 'ch2',
#count: 10,
}));
});
});
});
}
4 changes: 3 additions & 1 deletion pubnub/test/unit/dx/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ void main() {
computeV2Signature(keyset, requestType, path, queryParams, body);
expect(response, equals(expectedSign));
});
test('computeV2Signature should return valid signature when special characters included', () {
test(
'computeV2Signature should return valid signature when special characters included',
() {
PubNub.version = '1.0.0';
Core.version = '1.0.0';
Time.mock(DateTime.fromMillisecondsSinceEpoch(1234567890000));
Expand Down

0 comments on commit 508ae72

Please sign in to comment.