fetchMessages method

Future<BatchHistoryResult> fetchMessages(
  1. Set<String> channels, {
  2. Keyset? keyset,
  3. String? using,
  4. int? count,
  5. Timetoken? start,
  6. Timetoken? end,
  7. bool? reverse,
  8. bool? includeMeta,
  9. bool includeMessageActions = false,
  10. bool includeMessageType = true,
  11. bool includeCustomMessageType = false,
  12. bool includeUUID = true,
})

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),
  );
}