Skip to content

Commit

Permalink
PubNub SDK v1.4.4 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
client-engineering-bot committed Aug 18, 2020
1 parent 149a65c commit bbce022
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 44 deletions.
22 changes: 20 additions & 2 deletions .pubnub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ changelog:
-
changes:
-
text: "Fixes issue of exception from server when publishKey os null with publish call."
text: "Add flags in history v3 for including messageType and uuid."
type: feature
-
text: "Add support for fetch history with message actions."
type: feature
-
text: "Refactor for error message parsing for files."
type: improvement
date: Aug 19, 20
version: v1.4.4
-
changes:
-
text: "Fixes issue of exception from server when publishKey is null with publish call."
type: bug
-
text: "Fixes missing url component in file publish message for sendFile and support for message encryption."
Expand Down Expand Up @@ -211,6 +224,11 @@ features:
- STORAGE-MESSAGE-COUNT
- STORAGE-HISTORY-WITH-META
- STORAGE-FETCH-WITH-META
- STORAGE-FETCH-WITH-MESSAGE-ACTIONS
- STORAGE-HISTORY-WITH-INCLUDE-MESSAGE-TYPE
- STORAGE-HISTORY-WITH-INCLUDE-UUID
- STORAGE-FETCH-WITH-INCLUDE-MESSAGE-TYPE
- STORAGE-FETCH-WITH-INCLUDE-UUID
subscribe:
- SUBSCRIBE-CHANNELS
- SUBSCRIBE-CHANNEL-GROUPS
Expand Down Expand Up @@ -266,4 +284,4 @@ supported-platforms:
platforms:
- "Dart SDK >=2.6.0 <3.0.0"
version: "PubNub Dart SDK"
version: "1.4.3"
version: "1.4.4"
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [v1.4.4](https://github.com/pubnub/dart/releases/tag/v1.4.4)
August 19 2020

[Full Changelog](https://github.com/pubnub/dart/compare/v1.4.3...v1.4.4)

- 🌟️ Add flags in history v3 for including messageType and uuid.
- 🌟️ Add support for fetch history with message actions. Fixed the following issues reported by [@edissonaguilar](https://github.com/edissonaguilar): [#12](https://github.com/pubnub/dart/issues/12).
- ⭐️️ Refactor for error message parsing for files.

## [v1.4.3](https://github.com/pubnub/dart/releases/tag/v1.4.3)
August 5 2020

Expand Down
8 changes: 8 additions & 0 deletions lib/pubnub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export './src/dx/_endpoints/file.dart'
PublishFileMessageResult,
ListFilesResult,
DeleteFileResult,
FileDetail,
DownloadFileResult;
export './src/dx/_endpoints/presence.dart'
show HeartbeatResult, LeaveResult, HereNowResult, StateInfo;
Expand All @@ -25,6 +26,13 @@ export './src/dx/_endpoints/channel_group.dart'
ChannelGroupChangeChannelsResult,
ChannelGroupListChannelsResult,
ChannelGroupDeleteResult;
export './src/dx/_endpoints/history.dart'
show
FetchHistoryResult,
BatchHistoryResult,
BatchHistoryResultEntry,
CountMessagesResult,
DeleteMessagesResult;
export './src/dx/_endpoints/signal.dart' show SignalResult;
export './src/dx/_endpoints/push.dart'
show
Expand Down
2 changes: 1 addition & 1 deletion lib/src/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Core {
ParserModule parser;
CryptoModule crypto;

static String version = '1.4.3';
static String version = '1.4.4';

Core(
{Keyset defaultKeyset,
Expand Down
54 changes: 48 additions & 6 deletions lib/src/dx/_endpoints/history.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:pubnub/src/core/core.dart';
import 'package:pubnub/src/dx/_utils/utils.dart';
import 'package:pubnub/src/dx/subscribe/envelope.dart'
show MessageType, fromInt;

typedef decryptFunction = List<int> Function(CipherKey key, String data);

Expand Down Expand Up @@ -78,16 +80,26 @@ class BatchHistoryParams extends Parameters {
Timetoken start;
Timetoken end;
bool includeMeta;
bool includeMessageActions;
bool includeUUID;
bool includeMessageType;

BatchHistoryParams(this.keyset, this.channels,
{this.max, this.reverse, this.start, this.end, this.includeMeta})
{this.max,
this.reverse,
this.start,
this.end,
this.includeMeta,
this.includeMessageActions,
this.includeMessageType,
this.includeUUID})
: assert(channels.isNotEmpty);

@override
Request toRequest() {
var pathSegments = [
'v3',
'history',
includeMessageActions == true ? 'history-with-actions' : 'history',
'sub-key',
keyset.subscribeKey,
'channel',
Expand All @@ -100,6 +112,9 @@ class BatchHistoryParams extends Parameters {
if (start != null) 'start': '$start',
if (end != null) 'end': '$end',
if (includeMeta != null) 'include-_meta': '$includeMeta',
if (includeMessageType != null)
'include_message_type': '{$includeMessageType}',
if (includeUUID != null) 'include_uuid': '{$includeUUID}',
if (keyset.authKey != null) 'auth': '${keyset.authKey}',
if (keyset.uuid != null) 'uuid': '${keyset.uuid}'
};
Expand All @@ -112,36 +127,63 @@ class BatchHistoryParams extends Parameters {
class BatchHistoryResultEntry {
dynamic message;
Timetoken timetoken;
String uuid;
MessageType messageType;
Map<String, dynamic> actions;

BatchHistoryResultEntry._();

factory BatchHistoryResultEntry.fromJson(Map<String, dynamic> object,
{CipherKey cipherKey, Function decryptFunction}) {
return BatchHistoryResultEntry._()
..timetoken = Timetoken(object['timestamp'] as int)
..uuid = object['uuid']
..messageType = (object['message_type'] is int)
? fromInt(object['message_type'])
: null
..message = cipherKey == null
? object['message']
: decryptFunction(cipherKey, object['message']);
: decryptFunction(cipherKey, object['message'])
..actions = object['actions'];
}
}

class BatchHistoryResult extends Result {
Map<String, List<BatchHistoryResultEntry>> channels;
MoreHistory more;

BatchHistoryResult._();
BatchHistoryResult();

factory BatchHistoryResult.fromJson(Map<String, dynamic> object,
{CipherKey cipherKey, Function decryptFunction}) {
var result = DefaultResult.fromJson(object);

return BatchHistoryResult._()
return BatchHistoryResult()
..channels = (result.otherKeys['channels'] as Map<String, dynamic>).map(
(key, value) => MapEntry(
key,
(value as List<dynamic>)
.map((entry) => BatchHistoryResultEntry.fromJson(entry,
cipherKey: cipherKey, decryptFunction: decryptFunction))
.toList()));
.toList()))
..more = result.otherKeys['more'] != null
? MoreHistory.fromJson(result.otherKeys['more'])
: null;
}
}

class MoreHistory {
String url;
String start;
int count;

MoreHistory();

factory MoreHistory.fromJson(dynamic object) {
return MoreHistory()
..url = object['url'] as String
..start = object['start'] as String
..count = object['limit'] as int;
}
}

Expand Down
19 changes: 13 additions & 6 deletions lib/src/dx/_utils/custom_flow.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert' show utf8;
import 'package:xml/xml.dart' show XmlDocument;
import 'package:meta/meta.dart';

import 'package:pubnub/src/core/core.dart';
Expand All @@ -21,12 +23,17 @@ Future<R> customFlow<P extends Parameters, R>(

return result;
} on PubNubRequestFailureException catch (exception) {
var error = await core.parser.decode(exception.responseData);

if (error is Map) {
error = DefaultResult.fromJson(error);
var responseData = exception.responseData;
if (responseData.data != null) {
var details = utf8.decode(exception.responseData.data);
var messageNode =
XmlDocument.parse(details).rootElement.getElement('Message');
if (messageNode != null) {
details = messageNode.text;
}
throw PubNubException(
'${responseData.statusCode}\n${responseData.statusMessage}\n${exception.message}\n$details');
}

throw getExceptionFromAny(error);
throw PubNubException('${responseData.statusCode}');
}
}
2 changes: 1 addition & 1 deletion lib/src/dx/_utils/ensure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ class Ensure {
return;
}

throw InvariantException('is-equal', what);
throw InvariantException('is-equal', what, ['$otherValue']);
}
}
61 changes: 47 additions & 14 deletions lib/src/dx/batch/batch.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:pubnub/pubnub.dart';
import 'package:pubnub/src/core/core.dart';
import 'package:pubnub/src/dx/_utils/utils.dart';
import 'package:pubnub/src/dx/_endpoints/history.dart';
Expand All @@ -13,25 +14,57 @@ class BatchDx {
Future<BatchHistoryResult> fetchMessages(Set<String> channels,
{Keyset keyset,
String using,
int count,
int count = 25,
Timetoken start,
Timetoken end,
bool reverse,
bool includeMeta}) async {
bool includeMeta,
bool includeMessageActions = false,
bool includeMessageType = true,
bool includeUUID = true}) async {
keyset ??= _core.keysets.get(using, defaultIfNameIsNull: true);

return defaultFlow<BatchHistoryParams, BatchHistoryResult>(
logger: _logger,
core: _core,
params: BatchHistoryParams(keyset, channels,
max: count,
start: start,
end: end,
reverse: reverse,
includeMeta: includeMeta),
serialize: (object, [_]) => BatchHistoryResult.fromJson(object,
cipherKey: keyset.cipherKey,
decryptFunction: _core.crypto.decrypt));
if (includeMessageActions == true) {
Ensure(channels.length).isEqual(1,
'History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.');
}
var fetchMessagesResult = BatchHistoryResult()..channels = {};
BatchHistoryResult loopResult;
do {
loopResult = await defaultFlow<BatchHistoryParams, BatchHistoryResult>(
logger: _logger,
core: _core,
params: BatchHistoryParams(keyset, channels,
max: count,
start: start,
end: end,
reverse: reverse,
includeMeta: includeMeta,
includeMessageActions: includeMessageActions,
includeMessageType: includeMessageType,
includeUUID: includeUUID),
serialize: (object, [_]) => BatchHistoryResult.fromJson(object,
cipherKey: keyset.cipherKey,
decryptFunction: _core.crypto.decrypt));
loopResult.channels.forEach((channel, messages) => {
if (fetchMessagesResult.channels[channel] == null)
{
fetchMessagesResult.channels[channel] =
loopResult.channels[channel]
}
else
{
fetchMessagesResult.channels[channel]
.addAll(loopResult.channels[channel])
}
});
if (loopResult.more != null) {
var moreHistory = loopResult.more;
start = Timetoken(int.parse(moreHistory.start));
count = moreHistory.count;
}
} while (loopResult.more != null);
return fetchMessagesResult;
}

/// Get multiple channels' message count using one REST call.
Expand Down
1 change: 1 addition & 0 deletions lib/src/dx/message_action/message_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ mixin MessageActionDx on Core {
Ensure(type).isNotEmpty('message action type');
Ensure(value).isNotEmpty('message action value');
Ensure(timetoken).isNotNull('message timetoken');
Ensure(keyset.uuid).isNotNull('uuid');

var addMessageActionBody =
await super.parser.encode({'type': type, 'value': value});
Expand Down
3 changes: 1 addition & 2 deletions lib/src/net/net.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ class CustomRequestHandler extends RequestHandler {
_contents.completeError(PubNubRequestTimeoutException());
break;
case DioErrorType.RESPONSE:
_contents
.completeError(PubNubRequestFailureException(e.response.data));
_contents.completeError(PubNubRequestFailureException(e.response));
break;
case DioErrorType.DEFAULT:
default:
Expand Down
16 changes: 15 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
version: "1.2.2"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -260,6 +260,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.0"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
pointycastle:
dependency: transitive
description:
Expand Down Expand Up @@ -414,6 +421,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
xml:
dependency: "direct main"
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "4.4.0"
yaml:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion 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: 1.4.3
version: 1.4.4
homepage: https://www.pubnub.com/docs

environment:
Expand All @@ -14,6 +14,7 @@ dependencies:
cbor: ^3.1.0
encrypt: ^4.0.2
convert: ^2.0.0
xml: ^4.3.0
dev_dependencies:
pedantic: 1.9.0
test: 1.11.1
Expand Down
Loading

0 comments on commit bbce022

Please sign in to comment.