|
|
@ -21,6 +21,8 @@ abstract class NotificationsBlocStates { |
|
|
|
BehaviorSubject<Result<List<NotificationsNotification>>> get notifications; |
|
|
|
BehaviorSubject<Result<List<NotificationsNotification>>> get notifications; |
|
|
|
|
|
|
|
|
|
|
|
Stream<Exception> get errors; |
|
|
|
Stream<Exception> get errors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BehaviorSubject<int> get unreadCounter; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@RxBloc() |
|
|
|
@RxBloc() |
|
|
@ -35,10 +37,17 @@ class NotificationsBloc extends $NotificationsBloc { |
|
|
|
_$deleteNotificationEvent.listen((final notification) { |
|
|
|
_$deleteNotificationEvent.listen((final notification) { |
|
|
|
_wrapAction(() async => client.notifications.deleteNotification(notification.notificationId!)); |
|
|
|
_wrapAction(() async => client.notifications.deleteNotification(notification.notificationId!)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
_$deleteAllNotificationsEvent.listen((final notification) { |
|
|
|
_$deleteAllNotificationsEvent.listen((final notification) { |
|
|
|
_wrapAction(() async => client.notifications.deleteAllNotifications()); |
|
|
|
_wrapAction(() async => client.notifications.deleteAllNotifications()); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_notificationsSubject.listen((final result) { |
|
|
|
|
|
|
|
if (result.data != null) { |
|
|
|
|
|
|
|
_unreadCounterSubject.add(result.data!.length); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
_loadNotifications(); |
|
|
|
_loadNotifications(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -70,11 +79,13 @@ class NotificationsBloc extends $NotificationsBloc { |
|
|
|
|
|
|
|
|
|
|
|
final _notificationsSubject = BehaviorSubject<Result<List<NotificationsNotification>>>(); |
|
|
|
final _notificationsSubject = BehaviorSubject<Result<List<NotificationsNotification>>>(); |
|
|
|
final _errorsStreamController = StreamController<Exception>(); |
|
|
|
final _errorsStreamController = StreamController<Exception>(); |
|
|
|
|
|
|
|
final _unreadCounterSubject = BehaviorSubject<int>(); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
void dispose() { |
|
|
|
void dispose() { |
|
|
|
_notificationsSubject.close(); |
|
|
|
_notificationsSubject.close(); |
|
|
|
_errorsStreamController.close(); |
|
|
|
_errorsStreamController.close(); |
|
|
|
|
|
|
|
_unreadCounterSubject.close(); |
|
|
|
super.dispose(); |
|
|
|
super.dispose(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -83,4 +94,7 @@ class NotificationsBloc extends $NotificationsBloc { |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
Stream<Exception> _mapToErrorsState() => _errorsStreamController.stream.asBroadcastStream(); |
|
|
|
Stream<Exception> _mapToErrorsState() => _errorsStreamController.stream.asBroadcastStream(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
|
|
|
BehaviorSubject<int> _mapToUnreadCounterState() => _unreadCounterSubject; |
|
|
|
} |
|
|
|
} |
|
|
|