modifyMessage method

Future<ChatMessage> modifyMessage({
  1. required String messageId,
  2. ChatMessageBody? msgBody,
  3. Map<String, dynamic>? attributes,
})

Modifies a message.

After this method is called to modify a message, both the local message and the message on the server are modified.

This method can only modify a text message in one-to-one chats or group chats, but not in chat rooms.

Param messageId The ID of the message to modify.

Param msgBody The modified message body ChatMessageBody, only ChatTextMessageBody and ChatCustomMessageBody are supported.

Param attributes The custom attributes of the message.

Return The modified message.

Throws A description of the exception. See ChatError.

Implementation

Future<ChatMessage> modifyMessage({
  required String messageId,
  ChatMessageBody? msgBody,
  Map<String, dynamic>? attributes,
}) async {
  try {
    Map map = {'msgId': messageId};
    map.putIfNotNull('msgBody', msgBody?.toJson());
    map.putIfNotNull('attributes', attributes);

    Map result = await platform_interface.Client.instance.chatManager.callNativeMethod(
      ChatMethodKeys.modifyMessage,
      map,
    );
    ChatError.hasErrorFromResult(result);
    return ChatMessage.fromJson(result[ChatMethodKeys.modifyMessage]);
  } catch (e) {
    rethrow;
  }
}