fetchLatestMessageWithChatThreads method Null safety
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 {@link EMError}.
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.getMapValue(
ChatMethodKeys.fetchLastMessageWithChatThreads,
);
Map<String, EMMessage> ret = {};
if (map == null) {
return ret;
}
for (var key in map.keys) {
Map<String, Object> msgMap = map[key].cast<Map<String, Object>>();
ret[key] = EMMessage.fromJson(msgMap);
}
return ret;
} on EMError catch (e) {
throw e;
}
}