feat(notifications): option to disable in-app notifications

This commit is contained in:
Jagandeep Brar
2022-05-18 00:44:48 -04:00
parent de9281ce4c
commit da0c44c8b1
5 changed files with 22 additions and 0 deletions

View File

@@ -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",

View File

@@ -20,6 +20,7 @@ enum LunaDatabaseValue {
QUICK_ACTIONS_SEARCH,
USE_24_HOUR_TIME,
DEFAULT_LAUNCH_MODULE,
ENABLE_IN_APP_NOTIFICATIONS,
}
class LunaDatabase extends LunaModuleDatabase {
@@ -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;
}
}
@@ -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;
}
}
}

View File

@@ -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',

View File

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

View File

@@ -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",