Browse Source

refactor(neon): Cleanup push notifications bloc

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/934/head
jld3103 1 year ago
parent
commit
79760bf58b
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 3
      packages/neon/neon/lib/neon.dart
  2. 10
      packages/neon/neon/lib/src/blocs/push_notifications.dart

3
packages/neon/neon/lib/neon.dart

@ -51,7 +51,7 @@ Future<void> runNeon({
..addAccount(account)
..setActiveAccount(account);
}
final pushNotificationsBloc = PushNotificationsBloc(
PushNotificationsBloc(
accountsBloc,
globalOptions,
);
@ -69,7 +69,6 @@ Future<void> runNeon({
providers: [
NeonProvider<GlobalOptions>.value(value: globalOptions),
NeonProvider<AccountsBloc>.value(value: accountsBloc),
NeonProvider<PushNotificationsBloc>.value(value: pushNotificationsBloc),
NeonProvider<FirstLaunchBloc>.value(value: firstLaunchBloc),
NeonProvider<NextPushBloc>.value(value: nextPushBloc),
Provider<Iterable<AppImplementation>>(

10
packages/neon/neon/lib/src/blocs/push_notifications.dart

@ -6,7 +6,6 @@ import 'package:meta/meta.dart';
import 'package:neon/src/bloc/bloc.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/models/account.dart';
import 'package:neon/src/models/push_notification.dart';
import 'package:neon/src/platform/platform.dart';
import 'package:neon/src/settings/models/storage.dart';
import 'package:neon/src/utils/global_options.dart';
@ -18,9 +17,7 @@ import 'package:unifiedpush/unifiedpush.dart';
abstract interface class PushNotificationsBlocEvents {}
@internal
abstract interface class PushNotificationsBlocStates {
Stream<PushNotification> get notifications;
}
abstract interface class PushNotificationsBlocStates {}
@internal
class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents, PushNotificationsBlocStates {
@ -41,19 +38,14 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents,
late final _storage = const AppStorage(StorageKeys.notifications);
final GlobalOptions _globalOptions;
final _notificationsController = StreamController<PushNotification>();
StreamSubscription<List<Account>>? _accountsListener;
@override
void dispose() {
unawaited(_notificationsController.close());
unawaited(_accountsListener?.cancel());
_globalOptions.pushNotificationsEnabled.removeListener(_pushNotificationsEnabledListener);
}
@override
late Stream<PushNotification> notifications = _notificationsController.stream.asBroadcastStream();
String _keyLastEndpoint(final Account account) => 'last-endpoint-${account.id}';
Future<void> _pushNotificationsEnabledListener() async {

Loading…
Cancel
Save