|
|
@ -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 { |
|
|
|