Skip to content

Commit

Permalink
feat(notifications): option to disable in-app notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
JagandeepBrar committed May 18, 2022
1 parent de9281c commit da0c44c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@
"settings.EmailSentSuccessMessage": "An email to reset your password has been sent!",
"settings.EmailUpdated": "Email Updated",
"settings.EmailValidation": "Invalid Email Address",
"settings.EnableInAppNotifications": "Enable In-App Notifications",
"settings.EnableModule": "Enable {}",
"settings.EnabledProfile": "Enabled Profile",
"settings.EncryptionKey": "Encryption Key",
Expand Down
5 changes: 5 additions & 0 deletions lib/core/database/luna_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum LunaDatabaseValue {
QUICK_ACTIONS_SEARCH,
USE_24_HOUR_TIME,
DEFAULT_LAUNCH_MODULE,
ENABLE_IN_APP_NOTIFICATIONS,
}

class LunaDatabase extends LunaModuleDatabase {
Expand Down Expand Up @@ -167,6 +168,8 @@ extension LunaDatabaseValueExtension on LunaDatabaseValue {
return value is LunaModule;
case LunaDatabaseValue.NETWORKING_TLS_VALIDATION:
return value is bool;
case LunaDatabaseValue.ENABLE_IN_APP_NOTIFICATIONS:
return value is bool;
}
}

Expand Down Expand Up @@ -208,6 +211,8 @@ extension LunaDatabaseValueExtension on LunaDatabaseValue {
return LunaModule.DASHBOARD;
case LunaDatabaseValue.NETWORKING_TLS_VALIDATION:
return false;
case LunaDatabaseValue.ENABLE_IN_APP_NOTIFICATIONS:
return true;
}
}
}
2 changes: 2 additions & 0 deletions lib/firebase/messaging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class LunaFirebaseMessaging {
/// This listens on [FirebaseMessaging.onMessage], where the application must be open and in the foreground.
StreamSubscription<RemoteMessage> registerOnMessageListener() {
return onMessage.listen((message) {
if (LunaDatabaseValue.ENABLE_IN_APP_NOTIFICATIONS.data) return;

LunaModule? module = LunaModule.DASHBOARD.fromKey(message.data['module']);
showLunaSnackBar(
title: message.notification?.title ?? 'Unknown Content',
Expand Down
13 changes: 13 additions & 0 deletions lib/modules/settings/routes/notifications/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,25 @@ class _State extends State<_Widget> with LunaScrollControllerMixin {
trailing: const LunaIconButton.arrow(),
onTap: LunaLinks.NOTIFICATIONS_GETTING_STARTED.launch,
),
_enableInAppNotifications(),
LunaDivider(),
..._modules(),
],
);
}

Widget _enableInAppNotifications() {
return LunaBlock(
title: 'settings.EnableInAppNotifications'.tr(),
trailing: LunaDatabaseValue.ENABLE_IN_APP_NOTIFICATIONS.listen(
builder: (context, box, _) => LunaSwitch(
value: LunaDatabaseValue.ENABLE_IN_APP_NOTIFICATIONS.data,
onChanged: LunaDatabaseValue.ENABLE_IN_APP_NOTIFICATIONS.put,
),
),
);
}

List<Widget> _modules() {
List<SettingsNotificationsModuleTile> modules = [];
for (LunaModule module in LunaModule.values) {
Expand Down
1 change: 1 addition & 0 deletions localization/settings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"settings.EmailSentSuccessMessage": "An email to reset your password has been sent!",
"settings.EmailUpdated": "Email Updated",
"settings.EmailValidation": "Invalid Email Address",
"settings.EnableInAppNotifications": "Enable In-App Notifications",
"settings.EnableModule": "Enable {}",
"settings.EnabledProfile": "Enabled Profile",
"settings.EncryptionKey": "Encryption Key",
Expand Down

0 comments on commit da0c44c

Please sign in to comment.