fetchHistoryMessages method

  1. @Deprecated('Use [fetchHistoryMessagesByOption] instead')
Future<EMCursorResult<EMMessage>> fetchHistoryMessages({
  1. required String conversationId,
  2. EMConversationType type = EMConversationType.Chat,
  3. int pageSize = 20,
  4. EMSearchDirection direction = EMSearchDirection.Up,
  5. String startMsgId = '',
})

~english Gets historical messages of the conversation from the server with pagination.

Param conversationId The conversation ID.

Param type The conversation type. See EMConversationType.

Param pageSize The number of messages per page.

Param direction The message search direction. See EMSearchDirection.

Param startMsgId The ID of the message from which you start to get the historical messages. If null is passed, the SDK gets messages in the reverse chronological order.

Return The obtained messages and the cursor for the next query.

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

~chinese 从服务器分页获取历史消息。

Param conversationId 会话 ID。

Param type 会话类型,详见EMConversationType

Param pageSize 每页获取的消息数量。

Param direction 要搜索的消息方向. 见 EMSearchDirection.

Param startMsgId 获取历史消息的开始消息 ID,如果为空,从最新的消息向前开始获取。

Return 返回消息列表和用于继续获取历史消息的 EMCursorResult

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

Implementation

@Deprecated('Use [fetchHistoryMessagesByOption] instead')

/// ~english
/// Gets historical messages of the conversation from the server with pagination.
///
/// Param [conversationId] The conversation ID.
///
/// Param [type] The conversation type. See [EMConversationType].
///
/// Param [pageSize] The number of messages per page.
///
/// Param [direction] The message search direction. See [EMSearchDirection].
///
/// Param [startMsgId] The ID of the message from which you start to get the historical messages. If `null` is passed, the SDK gets messages in the reverse chronological order.
///
/// **Return** The obtained messages and the cursor for the next query.
///
/// **Throws** A description of the exception. See [EMError].
/// ~end
///
/// ~chinese
/// 从服务器分页获取历史消息。
///
/// Param [conversationId] 会话 ID。
///
/// Param [type] 会话类型,详见[EMConversationType]。
///
/// Param [pageSize] 每页获取的消息数量。
///
/// Param [direction] 要搜索的消息方向. 见 [EMSearchDirection].
///
/// Param [startMsgId] 获取历史消息的开始消息 ID,如果为空,从最新的消息向前开始获取。
///
/// **Return** 返回消息列表和用于继续获取历史消息的 [EMCursorResult]
///
/// **Throws**  如果有异常会在这里抛出,包含错误码和错误描述,详见 [EMError]。
/// ~end
Future<EMCursorResult<EMMessage>> fetchHistoryMessages({
  required String conversationId,
  EMConversationType type = EMConversationType.Chat,
  int pageSize = 20,
  EMSearchDirection direction = EMSearchDirection.Up,
  String startMsgId = '',
}) async {
  Map req = Map();
  req['convId'] = conversationId;
  req['type'] = conversationTypeToInt(type);
  req['pageSize'] = pageSize;
  req['startMsgId'] = startMsgId;
  req['direction'] = direction.index;
  Map result = await ChatChannel.invokeMethod(
      ChatMethodKeys.fetchHistoryMessages, req);
  try {
    EMError.hasErrorFromResult(result);
    return EMCursorResult<EMMessage>.fromJson(
        result[ChatMethodKeys.fetchHistoryMessages],
        dataItemCallback: (value) {
      return EMMessage.fromJson(value);
    });
  } on EMError catch (e) {
    throw e;
  }
}