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
    ..createdBefore = GroupChannelFilter.toSec(createdBefore)
    ..createdAfter = GroupChannelFilter.toSec(createdAfter);

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

  ChannelListQueryResponse<GroupChannel> res;
  try {
    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,
      ),
    );

    token = res.next;
    hasNext = res.next != '';
    for (final channel in res.channels) {
      channel.set(chat);
    }

    //+ [DBManager]
    if (chat.dbManager.isEnabled()) {
      await chat.dbManager.upsertGroupChannels(res.channels);
    }
    //- [DBManager]
  } catch (_) {
    isLoading = false;
    rethrow;
  }

  isLoading = false;
  return res.channels;
}