fetchConversation method

Future<ChatCursorResult<ChatConversation>> fetchConversation(
  1. {String? cursor,
  2. int pageSize = 20}
)

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 ChatError.

Implementation

Future<ChatCursorResult<ChatConversation>> fetchConversation({
  String? cursor,
  int pageSize = 20,
}) async {
  Map map = {
    "pageSize": pageSize,
  };
  map.putIfNotNull('cursor', cursor);
  Map result = await ChatChannel.invokeMethod(
    ChatMethodKeys.getConversationsFromServerWithCursor,
    map,
  );
  try {
    ChatError.hasErrorFromResult(result);
    return ChatCursorResult.fromJson(
        result[ChatMethodKeys.getConversationsFromServerWithCursor],
        dataItemCallback: (map) {
      return ChatConversation.fromJson(map);
    });
  } on ChatError catch (e) {
    throw e;
  }
}