publishFileMessage method

Future<PublishFileMessageResult> publishFileMessage(
  1. String channel,
  2. FileMessage message, {
  3. bool? storeMessage,
  4. int? ttl,
  5. dynamic meta,
  6. CipherKey? cipherKey,
  7. String? customMessageType,
  8. Keyset? keyset,
  9. String? using,
})

Allows to publish file message.

In case sendFile method doesn't publish message to channel, this method can be used to explicitly publish message

Provide cipherKey to encrypt the message. It takes precedence over Keyset.cipherKey.

You can override the default account configuration on message saving using storeMessage flag - true to save and false to discard. Leave this option unset if you want to use the default.

You can set a per-message time to live in storage using ttl option. If set to 0, message won't expire. If unset, expiration will fall back to default.

You can send additional information with meta parameter

If keyset is not provided, then it tries to obtain a keyset using name. If that fails, then it uses the default keyset. If that fails as well, then it will throw InvariantException.

Implementation

Future<PublishFileMessageResult> publishFileMessage(
    String channel, FileMessage message,
    {bool? storeMessage,
    int? ttl,
    dynamic meta,
    CipherKey? cipherKey,
    String? customMessageType,
    Keyset? keyset,
    String? using}) async {
  keyset ??= _core.keysets[using];
  Ensure(keyset.publishKey).isNotNull('publish key');

  var messagePayload = await _core.parser.encode(message);
  if (cipherKey != null ||
      keyset.cipherKey != null ||
      _core.crypto is CryptoModule) {
    messagePayload = (cipherKey != null ||
            !(keyset.cipherKey == _core.keysets.defaultKeyset.cipherKey))
        ? await _core.parser.encode(base64.encode(_core.crypto.encryptWithKey(
            cipherKey ?? keyset.cipherKey!, utf8.encode(messagePayload))))
        : await _core.parser.encode(
            base64.encode(_core.crypto.encrypt(utf8.encode(messagePayload))));
  }
  if (meta != null) meta = await _core.parser.encode(meta);
  return defaultFlow(
      keyset: keyset,
      core: _core,
      params: PublishFileMessageParams(keyset, channel, messagePayload,
          storeMessage: storeMessage,
          ttl: ttl,
          meta: meta,
          customMessageType: customMessageType),
      serialize: (object, [_]) => PublishFileMessageResult.fromJson(object));
}