Skip to content

Commit

Permalink
fix: notifications setting (#3903)
Browse files Browse the repository at this point in the history
* fix: notifications setting

* fix: remove dependency in reminder bloc

* test: remove redundant lines
  • Loading branch information
Xazin authored Nov 8, 2023
1 parent 17651bf commit 42e7317
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 22 deletions.
6 changes: 2 additions & 4 deletions frontend/appflowy_flutter/integration_test/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
});
}
Original file line number Diff line number Diff line change
@@ -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();
}
9 changes: 1 addition & 8 deletions frontend/appflowy_flutter/lib/startup/deps_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class _ApplicationWidgetState extends State<ApplicationWidget> {
)..readLocaleWhenAppLaunch(context),
),
BlocProvider<NotificationSettingsCubit>(
create: (_) => getIt<NotificationSettingsCubit>(),
create: (_) => NotificationSettingsCubit(),
),
BlocProvider<DocumentAppearanceCubit>(
create: (_) => DocumentAppearanceCubit()..fetch(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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(),
Expand Down

0 comments on commit 42e7317

Please sign in to comment.