computeOptions function

ComputedOptions computeOptions(
  1. ChatSendOptions options
)

Implementation

ComputedOptions computeOptions(ChatSendOptions options) {
  String messageType =
      options.message?.type ?? options.messageType ?? MessageType.TEXT;
  dynamic messageObj = options.message;

  if (messageObj == null) {
    if (![
      MessageType.TEXT,
      MessageType.IMAGE,
      MessageType.FILE,
      MessageType.MEDIA_EMBED,
      MessageType.GIF
    ].contains(messageType)) {
      throw Exception('Options.message is required');
    } else if (options.messageContent != null) {
      // use messageContent for backwards compatibility
      messageObj = SendMessage(
        content: options.messageContent!,
        type: messageType,
      );
    }
  }

  String to = options.recipient;
  if (to.isEmpty) {
    throw Exception('Options.to is required');
  }

  // Parse Reply Message
  if (messageType == MessageType.REPLY) {
    if (messageObj?.replyContent != null) {
      messageObj?.replyContent =
          _NestedContent.fromNestedContent(messageObj.replyContent);
    } else {
      throw Exception('Options.message is not properly defined for Reply');
    }
  }

  // Parse Composite Message
  if (messageType == MessageType.COMPOSITE) {
    if (messageObj?.compositeContent != null) {
      messageObj?.compositeContent =
          messageObj?.compositeContent?.map((nestedContent) {
        return _NestedContent.fromNestedContent(nestedContent);
      });
    } else {
      throw Exception('Options.message is not properly defined for Composite');
    }
  }

  return ComputedOptions(
    messageType: messageType,
    messageObj: messageObj,
    to: to,
    account: options.account,
    signer: options.signer,
    pgpPrivateKey: options.pgpPrivateKey,
  );
}