next method

  1. @override
Future<List<BaseMessage>> next()
override

Gets the list of next items.

Implementation

@override
Future<List<BaseMessage>> next() async {
  sbLog.i(StackTrace.current);

  if (isLoading) throw QueryInProgressException();
  if (!hasNext) return [];

  isLoading = true;

  final params = MessageListParams()
    ..previousResultSize = limit
    ..reverse = reverse
    ..customTypes = customTypesFilter
    ..messageType = messageTypeFilter
    ..senderIds = senderIdsFilter
    ..includeParentMessageInfo = includeParentMessageInfo
    ..replyType = replyType
    ..showSubChannelMessagesOnly = showSubChannelMessagesOnly;

  final res = await chat.apiClient.send<List<BaseMessage>>(
    ChannelMessagesGetRequest(
      chat,
      channelType: channelType,
      channelUrl: channelUrl,
      params: params.toJson(),
      timestamp: messageTimestamp ?? 0,
    ),
  );

  if (res.isNotEmpty) {
    final oldestMessage = reverse ? res.last : res.first;
    messageTimestamp = oldestMessage.createdAt;
  } else {
    messageTimestamp = null;
  }

  isLoading = false;
  hasNext = res.length == limit;
  return res;
}