fetchHistoryMessagesByOption method

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

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 ChatConversationType.Chat or ChatConversationType.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.

Implementation

Future<ChatCursorResult<ChatMessage>> fetchHistoryMessagesByOption(
  String conversationId,
  ChatConversationType 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 {
    ChatError.hasErrorFromResult(result);
    return ChatCursorResult<ChatMessage>.fromJson(
        result[ChatMethodKeys.fetchHistoryMessagesByOptions],
        dataItemCallback: (value) {
      return ChatMessage.fromJson(value);
    });
  } on ChatError catch (e) {
    throw e;
  }
}