copyMessage method

BaseMessage copyMessage(
  1. BaseMessage message,
  2. BaseChannel targetChannel, {
  3. OnMessageCallback? onCompleted,
})

Copies message to targetChannel.

It returns either UserMessage or FileMessage with MessageSendingStatus.pending and onCompleted will be invoked once the message has been sent completely. Channel event ChannelEventHandler.onMessageReceived will be invoked on all other members' end.

Implementation

BaseMessage copyMessage(
  BaseMessage message,
  BaseChannel targetChannel, {
  OnMessageCallback? onCompleted,
}) {
  if (message.channelUrl != channelUrl) {
    throw InvalidParameterError();
  }

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

  if (message is UserMessage) {
    final params = UserMessageParams.withMessage(message, deepCopy: false);
    if (params.pollId != null)
      throw SBError(
        message: 'Message with Poll can not be copied',
        code: ErrorCode.notSupportedError,
      );
    return targetChannel.sendUserMessage(
      params,
      onCompleted: onCompleted,
    );
  } else if (message is FileMessage) {
    final params = FileMessageParams.withMessage(message, deepCopy: false);
    return targetChannel.sendFileMessage(
      params,
      onCompleted: onCompleted,
    );
  } else {
    throw InvalidParameterError();
  }
}