fetchMessages method
Fetch messages for multiple channels using one call.
If includeMessageActions
is true
, then you can only pass in one channel in channels
.
Implementation
Future<BatchHistoryResult> fetchMessages(Set<String> channels,
{Keyset? keyset,
String? using,
int? count,
Timetoken? start,
Timetoken? end,
bool? reverse,
bool? includeMeta,
bool includeMessageActions = false,
bool includeMessageType = true,
bool includeCustomMessageType = false,
bool includeUUID = true}) async {
keyset ??= _core.keysets[using];
var SINGLE_CHANNEL_MAX = 100;
var MULTIPLE_CHANNEL_MAX = 25;
var max = count;
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.');
}
max ??= (channels.length > 1 || includeMessageActions == true)
? MULTIPLE_CHANNEL_MAX
: SINGLE_CHANNEL_MAX;
var params = BatchHistoryParams(keyset, channels,
max: max,
start: start,
end: end,
reverse: reverse,
includeMeta: includeMeta,
includeMessageActions: includeMessageActions,
includeMessageType: includeMessageType,
includeCustomMessageType: includeCustomMessageType,
includeUUID: includeUUID);
return defaultFlow<BatchHistoryParams, BatchHistoryResult>(
keyset: keyset,
core: _core,
params: params,
serialize: (object, [_]) => BatchHistoryResult.fromJson(object,
cipherKey: keyset?.cipherKey,
decryptFunction:
(keyset?.cipherKey == _core.keysets.defaultKeyset.cipherKey &&
_core.crypto is CryptoModule)
? _core.crypto.decrypt
: _core.crypto.decryptWithKey),
);
}