|
|
@ -29,17 +29,17 @@ abstract class NotificationsBlocStates { |
|
|
|
class NotificationsBloc extends $NotificationsBloc { |
|
|
|
class NotificationsBloc extends $NotificationsBloc { |
|
|
|
NotificationsBloc( |
|
|
|
NotificationsBloc( |
|
|
|
this.options, |
|
|
|
this.options, |
|
|
|
this.requestManager, |
|
|
|
this._requestManager, |
|
|
|
this.client, |
|
|
|
this._client, |
|
|
|
) { |
|
|
|
) { |
|
|
|
_$refreshEvent.listen((final _) => _loadNotifications()); |
|
|
|
_$refreshEvent.listen((final _) => _loadNotifications()); |
|
|
|
|
|
|
|
|
|
|
|
_$deleteNotificationEvent.listen((final id) { |
|
|
|
_$deleteNotificationEvent.listen((final id) { |
|
|
|
_wrapAction(() async => client.notifications.deleteNotification(id: id)); |
|
|
|
_wrapAction(() async => _client.notifications.deleteNotification(id: id)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
_$deleteAllNotificationsEvent.listen((final notification) { |
|
|
|
_$deleteAllNotificationsEvent.listen((final notification) { |
|
|
|
_wrapAction(() async => client.notifications.deleteAllNotifications()); |
|
|
|
_wrapAction(() async => _client.notifications.deleteAllNotifications()); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
_notificationsSubject.listen((final result) { |
|
|
|
_notificationsSubject.listen((final result) { |
|
|
@ -52,7 +52,7 @@ class NotificationsBloc extends $NotificationsBloc { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void _wrapAction(final Future Function() call) { |
|
|
|
void _wrapAction(final Future Function() call) { |
|
|
|
final stream = requestManager.wrapWithoutCache(call).asBroadcastStream(); |
|
|
|
final stream = _requestManager.wrapWithoutCache(call).asBroadcastStream(); |
|
|
|
stream.whereError().listen(_errorsStreamController.add); |
|
|
|
stream.whereError().listen(_errorsStreamController.add); |
|
|
|
stream.whereSuccess().listen((final _) async { |
|
|
|
stream.whereSuccess().listen((final _) async { |
|
|
|
_loadNotifications(); |
|
|
|
_loadNotifications(); |
|
|
@ -60,11 +60,11 @@ class NotificationsBloc extends $NotificationsBloc { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void _loadNotifications() { |
|
|
|
void _loadNotifications() { |
|
|
|
requestManager |
|
|
|
_requestManager |
|
|
|
.wrapNextcloud<List<NotificationsNotification>, NotificationsListNotifications>( |
|
|
|
.wrapNextcloud<List<NotificationsNotification>, NotificationsListNotifications>( |
|
|
|
client.id, |
|
|
|
_client.id, |
|
|
|
'notifications-notifications', |
|
|
|
'notifications-notifications', |
|
|
|
() async => client.notifications.listNotifications(), |
|
|
|
() async => _client.notifications.listNotifications(), |
|
|
|
(final response) => response.ocs!.data!, |
|
|
|
(final response) => response.ocs!.data!, |
|
|
|
previousData: _notificationsSubject.valueOrNull?.data, |
|
|
|
previousData: _notificationsSubject.valueOrNull?.data, |
|
|
|
) |
|
|
|
) |
|
|
@ -72,8 +72,8 @@ class NotificationsBloc extends $NotificationsBloc { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final NotificationsAppSpecificOptions options; |
|
|
|
final NotificationsAppSpecificOptions options; |
|
|
|
final RequestManager requestManager; |
|
|
|
final RequestManager _requestManager; |
|
|
|
final NextcloudClient client; |
|
|
|
final NextcloudClient _client; |
|
|
|
|
|
|
|
|
|
|
|
final _notificationsSubject = BehaviorSubject<Result<List<NotificationsNotification>>>(); |
|
|
|
final _notificationsSubject = BehaviorSubject<Result<List<NotificationsNotification>>>(); |
|
|
|
final _errorsStreamController = StreamController<Exception>(); |
|
|
|
final _errorsStreamController = StreamController<Exception>(); |
|
|
|