next method

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

Gets the list of next items. @since 4.0.13

Implementation

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

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

  isLoading = true;

  MessageSearchQueryResponse res;
  try {
    res = await chat.apiClient.send<MessageSearchQueryResponse>(
      MessageSearchRequest(
        chat,
        limit: limit,
        keyword: keyword,
        channelUrl: channelUrl,
        channelCustomType: channelCustomType,
        beforeToken: null,
        afterToken: token,
        token: null,
        startAt: messageTimestampFrom,
        endAt: messageTimestampTo,
        sortField: _messageSearchQueryOrderEnumMap[order],
        reverse: reverse,
        exactMatch: exactMatch,
        advancedQuery: advancedQuery,
        targetFields: targetFields,
      ),
    );

    hasNext = res.hasNext;
    totalCount = res.totalCount;
    token = res.next;
  } catch (_) {
    isLoading = false;
    rethrow;
  }

  isLoading = false;
  return res.results;
}