fetchHistoryMessagesByOption method

Future<EMCursorResult<EMMessage>> fetchHistoryMessagesByOption(
  1. String conversationId,
  2. EMConversationType type,
  3. {FetchMessageOptions? options,
  4. String? cursor,
  5. int pageSize = 50}
)

根据 FetchMessageOptions 从服务器分页获取指定会话的历史消息。

Param conversationId 会话 ID。

Param type 会话类型,只支持 EMConversationType.Chat 和群组 EMConversationType.GroupChat

Param options 查询历史消息的参数配置接口,详见 FetchMessageOptions

Param cursor 查询的起始游标位置。

Param pageSize 每页期望获取的消息条数。取值范围为 1,50

Implementation

Future<EMCursorResult<EMMessage>> fetchHistoryMessagesByOption(
  String conversationId,
  EMConversationType type, {
  FetchMessageOptions? options,
  String? cursor,
  int pageSize = 50,
}) async {
  Map req = Map();
  req.putIfNotNull('convId', conversationId);
  req.putIfNotNull('type', conversationTypeToInt(type));
  req.putIfNotNull('pageSize', pageSize);
  req.putIfNotNull('cursor', cursor);
  req.putIfNotNull('options', options?.toJson());
  Map result = await ChatChannel.invokeMethod(
      ChatMethodKeys.fetchHistoryMessagesByOptions, req);
  try {
    EMError.hasErrorFromResult(result);
    return EMCursorResult<EMMessage>.fromJson(
        result[ChatMethodKeys.fetchHistoryMessagesByOptions],
        dataItemCallback: (value) {
      return EMMessage.fromJson(value);
    });
  } on EMError catch (e) {
    throw e;
  }
}