next method

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

Gets the list of next items.

Implementation

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

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

  isLoading = true;

  final filter = GroupChannelFilter()
    ..customTypeStartsWith = customTypeStartsWithFilter
    ..customTypes = customTypesFilter
    ..memberStateFilter = myMemberStateFilter
    ..membersExactlyIn = userIdsExactFilter
    ..membersIncludeIn = userIdsIncludeFilter
    ..membersNicknameContains = nicknameContainsFilter
    ..nameContains = channelNameContainsFilter
    ..superMode = superChannelFilter
    ..publicMode = publicChannelFilter
    ..unreadFilter = unreadChannelFilter
    ..metadataOrderKey = metaDataOrderKeyFilter
    ..hiddenMode = hiddenChannelFilter
    ..metaDataKey = metaDataKey
    ..metaDataValues = metaDataValues
    ..metaDataValueStartsWithFilter = metaDataValueStartsWith;

  final options = [
    if (includeEmpty) ChannelListQueryIncludeOption.includeEmpty,
    if (includeFrozen) ChannelListQueryIncludeOption.includeFrozen,
    if (includeMetaData) ChannelListQueryIncludeOption.includeMetadata,
    if (includeChatNotification) ChannelListQueryIncludeOption.includeChatNotification,
    ChannelListQueryIncludeOption.includeMember,
    ChannelListQueryIncludeOption.includeReadReceipt,
    ChannelListQueryIncludeOption.includeDeliveryReceipt,
  ];

  final res =
      await chat.apiClient.send<ChannelListQueryResponse<GroupChannel>>(
    GroupChannelListRequest(
      chat,
      limit: limit,
      filter: filter,
      options: options,
      queryType: queryType,
      token: token,
      order: order,
      channelUrls: channelUrlsFilter,
      searchFields: searchFields,
      searchQuery: searchQuery,
    ),
  );

  for (final element in res.channels) {
    element.set(chat);
  }

  isLoading = false;
  token = res.next;
  hasNext = res.next != '';
  return res.channels;
}