diff --git a/Events.php b/Events.php
index 07c851e..000d1dc 100644
--- a/Events.php
+++ b/Events.php
@@ -2,7 +2,6 @@
namespace humhub\modules\fcmPush;
-
use humhub\modules\fcmPush\assets\FcmPushAsset;
use humhub\modules\fcmPush\assets\FirebaseAsset;
use humhub\modules\fcmPush\components\NotificationTargetProvider;
@@ -17,7 +16,6 @@
class Events
{
-
private const SESSION_VAR_LOGOUT = 'mobileAppHandleLogout';
private const SESSION_VAR_LOGIN = 'mobileAppHandleLogin';
@@ -82,7 +80,6 @@ public static function onNotificationInfoWidget($event)
$baseStack = $event->sender;
$baseStack->addWidget(PushNotificationInfoWidget::class);
-
}
public static function onLayoutAddonInit($event)
@@ -111,7 +108,6 @@ public static function onLayoutAddonInit($event)
FcmPushAsset::register(Yii::$app->view);
FirebaseAsset::register(Yii::$app->view);
-
}
public static function onAfterLogout()
@@ -123,5 +119,4 @@ public static function onAfterLogin()
{
Yii::$app->session->set(self::SESSION_VAR_LOGIN, 1);
}
-
-}
\ No newline at end of file
+}
diff --git a/assets/FcmPushAsset.php b/assets/FcmPushAsset.php
index 9dc1c41..4b01b9e 100644
--- a/assets/FcmPushAsset.php
+++ b/assets/FcmPushAsset.php
@@ -36,7 +36,5 @@ public static function register($view)
return parent::register($view);
}
-
-
}
}
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 9ad9e7a..8b73018 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -1,3 +1,7 @@
+Unreleased
+-----------------------------
+- Enh #24: Notification Grant Status
+
2.0.0-beta.6 (August 1, 2023)
-----------------------------
- Fix #25: Notification is not sent in user's language setting
diff --git a/resources/js/humhub.firebase.js b/resources/js/humhub.firebase.js
index 2574c8b..17ee6a9 100644
--- a/resources/js/humhub.firebase.js
+++ b/resources/js/humhub.firebase.js
@@ -22,6 +22,47 @@ humhub.module('firebase', function (module, require, $) {
}
};
+ const getNotificationPermissionContent = function () {
+ if (!("Notification" in window)) {
+ return 'This browser does not support notifications.';
+ }
+ console.log('Notification.permission:', Notification.permission);
+ return Notification.permission === "granted"
+ ? 'Push Notifications are active on this browser.
You can disable it in browser settings for this site.'
+ : 'You have blocked Push Notifications.
' +
+ (Notification.permission === 'denied'
+ ? 'You can enable it in browser settings for this site.'
+ : ' Click here to enable'); // 'default'
+ }
+
+ const showNotificationPermissionWindow = function () {
+ function handlePermission(permission) {
+ // set the button to shown or hidden, depending on what the user answers
+ addPushNotificationPermissionsInfo(permission, true);
+ }
+
+ // Let's check if the browser supports notifications
+ if (!("Notification" in window)) {
+ console.log("This browser does not support notifications.");
+ } else {
+ Notification.requestPermission().then((permission) => {
+ handlePermission(permission);
+ });
+ }
+ }
+
+ const addPushNotificationPermissionsInfo = function (permission, rewrite = false) {
+ if (rewrite) {
+ const contentContainer = document.getElementById('notificationPermissions');
+ contentContainer.innerHTML = getNotificationPermissionContent()
+ } else {
+ const content = '