fix: notifications setting (#3903)

* fix: notifications setting

* fix: remove dependency in reminder bloc

* test: remove redundant lines
This commit is contained in:
Mathias Mogensen 2023-11-09 00:32:10 +01:00 committed by GitHub
parent 17651bf64c
commit 42e7317cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 22 deletions

View File

@ -19,8 +19,7 @@ import 'document/document_test_runner.dart' as document_test_runner;
import 'empty_test.dart' as first_test;
import 'hotkeys_test.dart' as hotkeys_test;
import 'import_files_test.dart' as import_files_test;
import 'settings/user_icon_test.dart' as user_icon_test;
import 'settings/user_language_test.dart' as user_language_test;
import 'settings/settings_runner.dart' as settings_test_runner;
import 'share_markdown_test.dart' as share_markdown_test;
import 'sidebar/sidebar_test_runner.dart' as sidebar_test_runner;
import 'switch_folder_test.dart' as switch_folder_test;
@ -75,8 +74,7 @@ void main() {
appearance_test_runner.main();
// User settings
user_icon_test.main();
user_language_test.main();
settings_test_runner.main();
if (isCloudEnabled) {
auth_test_runner.main();

View File

@ -0,0 +1,41 @@
import 'package:appflowy/workspace/application/settings/settings_dialog_bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import '../util/util.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('board add row test', () {
testWidgets('Add card from header', (tester) async {
await tester.initializeAppFlowy();
await tester.tapGoButton();
await tester.openSettings();
await tester.openSettingsPage(SettingsPage.notifications);
await tester.pumpAndSettle();
final switchFinder = find.byType(Switch);
// Defaults to enabled
Switch switchWidget = tester.widget(switchFinder);
expect(switchWidget.value, true);
// Disable
await tester.tap(switchFinder);
await tester.pumpAndSettle();
switchWidget = tester.widget(switchFinder);
expect(switchWidget.value, false);
// Enable again
await tester.tap(switchFinder);
await tester.pumpAndSettle();
switchWidget = tester.widget(switchFinder);
expect(switchWidget.value, true);
});
});
}

View File

@ -0,0 +1,13 @@
import 'package:integration_test/integration_test.dart';
import 'notifications_settings_test.dart' as notifications_settings_test;
import 'user_icon_test.dart' as user_icon_test;
import 'user_language_test.dart' as user_language_test;
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
notifications_settings_test.main();
user_icon_test.main();
user_language_test.main();
}

View File

@ -19,7 +19,6 @@ import 'package:appflowy/user/presentation/router.dart';
import 'package:appflowy/workspace/application/edit_panel/edit_panel_bloc.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/notifications/notification_action_bloc.dart';
import 'package:appflowy/workspace/application/settings/notifications/notification_settings_cubit.dart';
import 'package:appflowy/workspace/application/settings/prelude.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
import 'package:appflowy/workspace/application/user/prelude.dart';
@ -164,13 +163,7 @@ void _resolveHomeDeps(GetIt getIt) {
getIt.registerLazySingleton<TabsBloc>(() => TabsBloc());
getIt.registerSingleton<NotificationSettingsCubit>(
NotificationSettingsCubit(),
);
getIt.registerSingleton<ReminderBloc>(
ReminderBloc(notificationSettings: getIt<NotificationSettingsCubit>()),
);
getIt.registerSingleton<ReminderBloc>(ReminderBloc());
}
void _resolveFolderDeps(GetIt getIt) {

View File

@ -131,7 +131,7 @@ class _ApplicationWidgetState extends State<ApplicationWidget> {
)..readLocaleWhenAppLaunch(context),
),
BlocProvider<NotificationSettingsCubit>(
create: (_) => getIt<NotificationSettingsCubit>(),
create: (_) => NotificationSettingsCubit(),
),
BlocProvider<DocumentAppearanceCubit>(
create: (_) => DocumentAppearanceCubit()..fetch(),

View File

@ -4,10 +4,10 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/reminder/reminder_extension.dart';
import 'package:appflowy/user/application/reminder/reminder_service.dart';
import 'package:appflowy/user/application/user_settings_service.dart';
import 'package:appflowy/workspace/application/notifications/notification_action.dart';
import 'package:appflowy/workspace/application/notifications/notification_action_bloc.dart';
import 'package:appflowy/workspace/application/notifications/notification_service.dart';
import 'package:appflowy/workspace/application/settings/notifications/notification_settings_cubit.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:bloc/bloc.dart';
@ -20,16 +20,11 @@ import 'package:freezed_annotation/freezed_annotation.dart';
part 'reminder_bloc.freezed.dart';
class ReminderBloc extends Bloc<ReminderEvent, ReminderState> {
final NotificationSettingsCubit _notificationSettings;
late final NotificationActionBloc actionBloc;
late final ReminderService reminderService;
late final Timer timer;
ReminderBloc({
required NotificationSettingsCubit notificationSettings,
}) : _notificationSettings = notificationSettings,
super(ReminderState()) {
ReminderBloc() : super(ReminderState()) {
actionBloc = getIt<NotificationActionBloc>();
reminderService = const ReminderService();
timer = _periodicCheck();
@ -146,7 +141,7 @@ class ReminderBloc extends Bloc<ReminderEvent, ReminderState> {
Timer _periodicCheck() {
return Timer.periodic(
const Duration(minutes: 1),
(_) {
(_) async {
final now = DateTime.now();
for (final reminder in state.upcomingReminders) {
@ -159,7 +154,9 @@ class ReminderBloc extends Bloc<ReminderEvent, ReminderState> {
);
if (scheduledAt.isBefore(now)) {
if (_notificationSettings.state.isNotificationsEnabled) {
final notificationSettings =
await UserSettingsBackendService().getNotificationSettings();
if (notificationSettings.notificationsEnabled) {
NotificationMessage(
identifier: reminder.id,
title: LocaleKeys.reminderNotification_title.tr(),