copyMessage method

BaseMessage copyMessage(
  1. BaseMessage message,
  2. BaseChannel targetChannel,
  3. {BaseMessageHandler? handler}
)

Copies a message from this channel to the target channel.

Implementation

BaseMessage copyMessage(
  BaseMessage message,
  BaseChannel targetChannel, {
  BaseMessageHandler? handler,
}) {
  sbLog.i(StackTrace.current, 'message: ${message.message}');
  checkUnsupportedAction();

  if (message.channelUrl != channelUrl) {
    throw InvalidParameterException();
  }

  // Do not copy [extendedMessage] in message.
  message.extendedMessage.clear();

  if (message is UserMessage) {
    final params =
        UserMessageCreateParams.withMessage(message, deepCopy: false);
    if (params.pollId != null) {
      throw InvalidParameterException();
    }
    return targetChannel.sendUserMessage(
      params,
      handler: handler,
    );
  } else if (message is FileMessage) {
    final params =
        FileMessageCreateParams.withMessage(message, deepCopy: false);
    return targetChannel.sendFileMessage(
      params,
      handler: handler,
    );
  } else {
    throw InvalidParameterException();
  }
}