sendMessage method

Future<ChatMessage> sendMessage(
  1. ChatMessage message,
  2. {void callback(
    1. void onSuccess(
      1. ChatMessage
      )?,
    2. void onError(
      1. ChatMessage
      )?,
    3. void onProgress(
      1. int
      )?
    )?}
)

Sends a message.

Note For attachment messages such as voice, image, or video messages, the SDK automatically uploads the attachment. You can set whether to upload the attachment to the chat sever using ChatOptions.serverTransfer.

To listen for the status of sending messages, call ChatManager.addMessageEvent.

Param message The message object to be sent: ChatMessage.

Throws A description of the exception. See ChatError.

Implementation

Future<ChatMessage> sendMessage(
  ChatMessage message, {
  void Function(
    void Function(ChatMessage)? onSuccess,
    void Function(ChatMessage)? onError,
    void Function(int)? onProgress,
  )? callback,
}) async {
  message.status = MessageStatus.PROGRESS;
  Map result = await ChatChannel.invokeMethod(
      ChatMethodKeys.sendMessage, message.toJson());
  try {
    ChatError.hasErrorFromResult(result);
    ChatMessage msg =
        ChatMessage.fromJson(result[ChatMethodKeys.sendMessage]);
    message.from = msg.from;
    message.to = msg.to;
    message.status = msg.status;
    return message;
  } on ChatError catch (e) {
    throw e;
  }
}