Browse Source

Merge pull request #934 from nextcloud/refactor/push-notifications-bloc

refactor(neon): Cleanup push notifications bloc
pull/938/head
Kate 1 year ago committed by GitHub
parent
commit
cfc268e567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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) ..addAccount(account)
..setActiveAccount(account); ..setActiveAccount(account);
} }
final pushNotificationsBloc = PushNotificationsBloc( PushNotificationsBloc(
accountsBloc, accountsBloc,
globalOptions, globalOptions,
); );
@ -69,7 +69,6 @@ Future<void> runNeon({
providers: [ providers: [
NeonProvider<GlobalOptions>.value(value: globalOptions), NeonProvider<GlobalOptions>.value(value: globalOptions),
NeonProvider<AccountsBloc>.value(value: accountsBloc), NeonProvider<AccountsBloc>.value(value: accountsBloc),
NeonProvider<PushNotificationsBloc>.value(value: pushNotificationsBloc),
NeonProvider<FirstLaunchBloc>.value(value: firstLaunchBloc), NeonProvider<FirstLaunchBloc>.value(value: firstLaunchBloc),
NeonProvider<NextPushBloc>.value(value: nextPushBloc), NeonProvider<NextPushBloc>.value(value: nextPushBloc),
Provider<Iterable<AppImplementation>>( 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/bloc/bloc.dart';
import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/models/account.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/platform/platform.dart';
import 'package:neon/src/settings/models/storage.dart'; import 'package:neon/src/settings/models/storage.dart';
import 'package:neon/src/utils/global_options.dart'; import 'package:neon/src/utils/global_options.dart';
@ -18,9 +17,7 @@ import 'package:unifiedpush/unifiedpush.dart';
abstract interface class PushNotificationsBlocEvents {} abstract interface class PushNotificationsBlocEvents {}
@internal @internal
abstract interface class PushNotificationsBlocStates { abstract interface class PushNotificationsBlocStates {}
Stream<PushNotification> get notifications;
}
@internal @internal
class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents, PushNotificationsBlocStates { class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents, PushNotificationsBlocStates {
@ -41,19 +38,14 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents,
late final _storage = const AppStorage(StorageKeys.notifications); late final _storage = const AppStorage(StorageKeys.notifications);
final GlobalOptions _globalOptions; final GlobalOptions _globalOptions;
final _notificationsController = StreamController<PushNotification>();
StreamSubscription<List<Account>>? _accountsListener; StreamSubscription<List<Account>>? _accountsListener;
@override @override
void dispose() { void dispose() {
unawaited(_notificationsController.close());
unawaited(_accountsListener?.cancel()); unawaited(_accountsListener?.cancel());
_globalOptions.pushNotificationsEnabled.removeListener(_pushNotificationsEnabledListener); _globalOptions.pushNotificationsEnabled.removeListener(_pushNotificationsEnabledListener);
} }
@override
late Stream<PushNotification> notifications = _notificationsController.stream.asBroadcastStream();
String _keyLastEndpoint(final Account account) => 'last-endpoint-${account.id}'; String _keyLastEndpoint(final Account account) => 'last-endpoint-${account.id}';
Future<void> _pushNotificationsEnabledListener() async { Future<void> _pushNotificationsEnabledListener() async {

Loading…
Cancel
Save