You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.8 KiB
70 lines
1.8 KiB
2 years ago
|
part of '../neon_notifications.dart';
|
||
2 years ago
|
|
||
|
abstract class NotificationsBlocEvents {
|
||
2 years ago
|
void deleteNotification(final int id);
|
||
2 years ago
|
|
||
|
void deleteAllNotifications();
|
||
|
}
|
||
|
|
||
|
abstract class NotificationsBlocStates {
|
||
2 years ago
|
BehaviorSubject<Result<List<NextcloudNotificationsNotification>>> get notifications;
|
||
2 years ago
|
|
||
2 years ago
|
BehaviorSubject<int> get unreadCounter;
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
class NotificationsBloc extends InteractiveBloc implements NotificationsBlocEvents, NotificationsBlocStates {
|
||
2 years ago
|
NotificationsBloc(
|
||
|
this.options,
|
||
2 years ago
|
this._requestManager,
|
||
|
this._client,
|
||
2 years ago
|
) {
|
||
2 years ago
|
notifications.listen((final result) {
|
||
2 years ago
|
if (result.data != null) {
|
||
2 years ago
|
unreadCounter.add(result.data!.length);
|
||
2 years ago
|
}
|
||
|
});
|
||
|
|
||
2 years ago
|
unawaited(refresh());
|
||
2 years ago
|
}
|
||
|
|
||
|
final NotificationsAppSpecificOptions options;
|
||
2 years ago
|
final RequestManager _requestManager;
|
||
|
final NextcloudClient _client;
|
||
2 years ago
|
|
||
|
@override
|
||
|
void dispose() {
|
||
2 years ago
|
unawaited(notifications.close());
|
||
|
unawaited(unreadCounter.close());
|
||
2 years ago
|
super.dispose();
|
||
|
}
|
||
|
|
||
|
@override
|
||
2 years ago
|
BehaviorSubject<Result<List<NextcloudNotificationsNotification>>> notifications =
|
||
|
BehaviorSubject<Result<List<NextcloudNotificationsNotification>>>();
|
||
2 years ago
|
|
||
|
@override
|
||
|
BehaviorSubject<int> unreadCounter = BehaviorSubject<int>();
|
||
2 years ago
|
|
||
|
@override
|
||
2 years ago
|
Future refresh() async {
|
||
2 years ago
|
await _requestManager
|
||
|
.wrapNextcloud<List<NextcloudNotificationsNotification>, NextcloudNotificationsListNotifications>(
|
||
2 years ago
|
_client.id,
|
||
|
'notifications-notifications',
|
||
|
notifications,
|
||
|
() async => _client.notifications.listNotifications(),
|
||
|
(final response) => response.ocs.data,
|
||
|
);
|
||
|
}
|
||
2 years ago
|
|
||
|
@override
|
||
2 years ago
|
void deleteAllNotifications() {
|
||
|
wrapAction(() async => _client.notifications.deleteAllNotifications());
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void deleteNotification(final int id) {
|
||
|
wrapAction(() async => _client.notifications.deleteNotification(id: id));
|
||
|
}
|
||
2 years ago
|
}
|