more method
Fetches more messages and stores them in messages.
Implementation
Future<FetchHistoryResult> more() async {
var result = await defaultFlow(
keyset: _keyset,
core: _core,
params: FetchHistoryParams(_keyset, _channel.name,
reverse: _order.choose(ascending: true, descending: false),
count: _chunkSize,
start: _cursor,
includeToken: true),
serialize: (object, [_]) => FetchHistoryResult.fromJson(object));
if (result.messages.length < _chunkSize) {
_hasMoreOverride = true;
}
if (_startTimetoken == null && _endTimetoken == null) {
_startTimetoken = result.startTimetoken;
_endTimetoken = result.endTimetoken;
}
if (_order == ChannelHistoryOrder.descending) {
_cursor = result.startTimetoken;
if (result.startTimetoken.value != BigInt.zero) {
_startTimetoken = result.startTimetoken;
}
} else {
_cursor = result.endTimetoken;
if (result.endTimetoken.value != BigInt.zero) {
_endTimetoken = result.endTimetoken;
}
}
_messages.addAll(await Future.wait(result.messages.map((message) async {
PubNubException? error;
if (_keyset.cipherKey != null || _core.crypto is CryptoModule) {
try {
if (!(message['message'] is String)) {
throw FormatException('not a base64 string.');
}
message['message'] = _keyset.cipherKey ==
_core.keysets.defaultKeyset.cipherKey
? await _core.parser.decode(utf8.decode(_core.crypto
.decrypt(base64.decode(message['message'] as String))))
: await _core.parser.decode(utf8.decode(_core.crypto
.encryptWithKey(_keyset.cipherKey!,
base64.decode(message['message'] as String).toList())));
} on CryptoException catch (e) {
error = e;
} on FormatException catch (e) {
error = PubNubException(
'Can not decrypt the message payload. Please check keyset or crypto configuration. ${e.message}');
}
}
return BaseMessage(
originalMessage: message,
publishedAt: Timetoken(BigInt.from(message['timetoken'])),
content: message['message'],
error: error);
})));
return result;
}