fetchLatestMessageWithChatThreads method

Future<Map<String, EMMessage>> fetchLatestMessageWithChatThreads({
  1. required List<String> chatThreadIds,
})

~english Get the latest news of the specified Chat Thread list from the server.

Param chatThreadIds Chat Thread id list. The list length is not greater than 20.

Return returns a Map collection, the key is the chat thread ID, and the value is the latest message object of the chat thread.

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

~chinese 从服务器批量获取指定子区中的最新一条消息。

Param chatThreadIds 要查询的子区 ID 列表,每次最多可传 20 个子区。

Return 若调用成功,返回子区的最新一条消息列表;失败则抛出异常。

Throws 如果有异常会在此抛出,包括错误码和错误信息,详见 EMError。 ~end

Implementation

Future<Map<String, EMMessage>> fetchLatestMessageWithChatThreads({
  required List<String> chatThreadIds,
}) async {
  Map req = {
    "threadIds": chatThreadIds,
  };
  Map result = await _channel.invokeMethod(
    ChatMethodKeys.fetchLastMessageWithChatThreads,
    req,
  );
  try {
    EMError.hasErrorFromResult(result);
    Map? map = result[ChatMethodKeys.fetchLastMessageWithChatThreads];
    Map<String, EMMessage> ret = {};
    if (map == null) {
      return ret;
    }

    for (var key in map.keys) {
      Map<String, dynamic> msgMap = map[key];
      ret[key] = EMMessage.fromJson(msgMap);
    }
    return ret;
  } on EMError catch (e) {
    throw e;
  }
}