fetchHistoryMessages method

Future<ChatCursorResult<ChatMessage>> fetchHistoryMessages(
  1. {required String conversationId,
  2. ChatConversationType type = ChatConversationType.Chat,
  3. int pageSize = 20,
  4. ChatSearchDirection direction = ChatSearchDirection.Up,
  5. String startMsgId = ''}

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

Param conversationId The conversation ID.

Param type The conversation type. See ChatConversationType.

Param pageSize The number of messages per page.

Param direction The message search direction. See ChatSearchDirection.

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


Future<ChatCursorResult<ChatMessage>> fetchHistoryMessages({
  required String conversationId,
  ChatConversationType type = ChatConversationType.Chat,
  int pageSize = 20,
  ChatSearchDirection direction = ChatSearchDirection.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 {
    return ChatCursorResult<ChatMessage>.fromJson(
        dataItemCallback: (value) {
      return ChatMessage.fromJson(value);
  } on ChatError catch (e) {
    throw e;