blocklist property

  1. @override
BlocklistPaginated blocklist
latefinal

Returns Paginated of Users blocked by the authenticated MyUser.

Implementation

@override
late final BlocklistPaginated blocklist = BlocklistPaginated(
  pagination: Pagination(
    onKey: (e) => e.userId,
    perPage: 15,
    provider: DriftGraphQlPageProvider(
      driftProvider: DriftPageProvider(
        fetch: ({required after, required before, UserId? around}) async {
          return await _blocklistLocal.records(limit: after + before + 1);
        },
        onKey: (e) => e.value.userId,
        onCursor: (e) => e?.cursor,
        add: (e, {bool toView = true}) async {
          await _blocklistLocal.upsertBulk(e);
        },
        delete: (e) async => await _blocklistLocal.delete(e),
        reset: () async => await _blocklistLocal.clear(),
        isFirst:
            (_) =>
                _sessionLocal.data[me]?.blocklistSynchronized == true &&
                blocklist.rawLength >= (_blocklistCount ?? double.infinity),
        isLast:
            (_) =>
                _sessionLocal.data[me]?.blocklistSynchronized == true &&
                blocklist.rawLength >= (_blocklistCount ?? double.infinity),
        compare: (a, b) => a.value.compareTo(b.value),
      ),
      graphQlProvider: GraphQlPageProvider(
        fetch: ({after, before, first, last}) async {
          final Page<DtoBlocklistRecord, BlocklistCursor> page =
              await _blocklist(
                after: after,
                before: before,
                first: first,
                last: last,
              );

          if (page.info.hasNext == false) {
            _sessionLocal.upsert(
              me,
              SessionData(blocklistSynchronized: true),
            );
          }

          return page;
        },
      ),
    ),
    compare: (a, b) => a.value.compareTo(b.value),
  ),
  transform: ({required DtoBlocklistRecord data, RxUser? previous}) {
    return previous ?? _userRepository.get(data.userId);
  },
);