fetchConversation method

  1. @Deprecated('Use fetchConversationsByOptions instead')
Future<EMCursorResult<EMConversation>> fetchConversation({
  1. String? cursor,
  2. int pageSize = 20,
})

~english Get the list of conversations from the server with pagination.

The SDK retrieves the list of conversations in the reverse chronological order of their active time (the timestamp of the last message). If there is no message in the conversation, the SDK retrieves the list of conversations in the reverse chronological order of their creation time.

Param cursor The position from which to start getting data. The SDK retrieves conversations from the latest active one if this parameter is not set.

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

Return The conversation list of the current user.

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

~chinese 从服务器分页获取会话列表。

SDK 按照会话活跃时间(会话的最后一条消息的时间戳)倒序返回会话列表。 若会话中没有消息,则 SDK 按照会话创建时间的倒序返回会话列表。

Param cursor 查询的开始位置,如不传, SDK 从最新活跃的会话开始获取。

Param pageSize 每页期望返回的会话数量。取值范围为 1,50

Return 当前用户的会话列表。

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

Implementation

@Deprecated('Use fetchConversationsByOptions instead')

/// ~english
/// Get the list of conversations from the server with pagination.
///
/// The SDK retrieves the list of conversations in the reverse chronological order of their active time (the timestamp of the last message).
/// If there is no message in the conversation, the SDK retrieves the list of conversations in the reverse chronological order of their creation time.
///
/// Param [cursor] The position from which to start getting data. The SDK retrieves conversations from the latest active one if this parameter is not set.
///
/// Param [pageSize] The number of conversations that you expect to get on each page. The value range is [1,50].
///
/// **Return** The conversation list of the current user.
///
/// **Throws** A description of the exception. See [EMError].
/// ~end
///
/// ~chinese
/// 从服务器分页获取会话列表。
///
/// SDK 按照会话活跃时间(会话的最后一条消息的时间戳)倒序返回会话列表。
/// 若会话中没有消息,则 SDK 按照会话创建时间的倒序返回会话列表。
///
/// Param [cursor] 查询的开始位置,如不传, SDK 从最新活跃的会话开始获取。
///
/// Param [pageSize] 每页期望返回的会话数量。取值范围为 [1,50]。
///
/// **Return** 当前用户的会话列表。
///
/// **Throws**  如果有异常会在这里抛出,包含错误码和错误描述,详见 [EMError]。
/// ~end
Future<EMCursorResult<EMConversation>> fetchConversation({
  String? cursor,
  int pageSize = 20,
}) async {
  Map map = {
    "pageSize": pageSize,
  };
  map.putIfNotNull('cursor', cursor);
  Map result = await ChatChannel.invokeMethod(
    ChatMethodKeys.getConversationsFromServerWithCursor,
    map,
  );
  try {
    EMError.hasErrorFromResult(result);
    return EMCursorResult.fromJson(
        result[ChatMethodKeys.getConversationsFromServerWithCursor],
        dataItemCallback: (map) {
      return EMConversation.fromJson(map);
    });
  } on EMError catch (e) {
    throw e;
  }
}