loadMessage method

Future<EMMessage?> loadMessage(
  1. String messageId
)

~english Loads a message from the local database by message ID.

Param messageId The message ID.

Return The message object specified by the message ID. Returns null if the message does not exist.

Throws A description of the exception. See EMError. ~end

~chinese 从本地数据库获取指定 ID 的消息对象。

Param messageId 消息 ID。

Return 根据指定 ID 获取的消息对象,如果消息不存在会返回空值。

Throws 如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError。 ~end

Implementation

Future<EMMessage?> loadMessage(String messageId) async {
  Map req = {"msg_id": messageId};
  Map<String, dynamic> result =
      await ChatChannel.invokeMethod(ChatMethodKeys.getMessage, req);
  try {
    EMError.hasErrorFromResult(result);
    if (result.containsKey(ChatMethodKeys.getMessage)) {
      return EMMessage.fromJson(result[ChatMethodKeys.getMessage]);
    } else {
      return null;
    }
  } on EMError catch (e) {
    throw e;
  }
}