part of '../neon_notifications.dart'; abstract interface class NotificationsBlocEvents { void deleteNotification(final int id); void deleteAllNotifications(); } abstract interface class NotificationsBlocStates { BehaviorSubject>> get notifications; BehaviorSubject get unreadCounter; } class NotificationsBloc extends InteractiveBloc implements NotificationsBlocInterface, NotificationsBlocEvents, NotificationsBlocStates { NotificationsBloc( this.options, this._requestManager, this._client, ) { notifications.listen((final result) { if (result.hasData) { unreadCounter.add(result.requireData.length); } }); unawaited(refresh()); } @override final NotificationsAppSpecificOptions options; final RequestManager _requestManager; final NextcloudClient _client; @override void dispose() { unawaited(notifications.close()); unawaited(unreadCounter.close()); super.dispose(); } @override BehaviorSubject>> notifications = BehaviorSubject>>(); @override BehaviorSubject unreadCounter = BehaviorSubject(); @override Future refresh() async { await _requestManager.wrapNextcloud, NotificationsListNotifications>( _client.id, 'notifications-notifications', notifications, () async => _client.notifications.listNotifications(), (final response) => response.ocs.data.toList(), ); } @override void deleteAllNotifications() { wrapAction(() async => _client.notifications.deleteAllNotifications()); } @override void deleteNotification(final int id) { wrapAction(() async => _client.notifications.deleteNotification(id: id)); } }