fetchHistoryMessagesByOption method

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

~english Gets historical messages of a conversation from the server according to FetchMessageOptions.

Param conversationId The conversation ID, which is the user ID of the peer user for one-to-one chat, but the group ID for group chat.

Param type The conversation type. You can set this parameter only to EMConversationType.Chat or EMConversationType.GroupChat.

Param options The parameter configuration class for pulling historical messages from the server. See FetchMessageOptions.

Param cursor The cursor position from which to start querying data.

Param pageSize The number of messages that you expect to get on each page. The value range is 1,50. ~end

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

Param conversationId 会话 ID。

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

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

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

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

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;
  }
}