From f0714c810645838280faaed04a9413fd5f926e0f Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 12 Sep 2023 18:27:01 +0200 Subject: [PATCH] [Glitch] Fix notification permissions being requested immediately after login Port f5f4f409558183c42fef9ffc287e8da0e461fd1f to glitch-soc Signed-off-by: Claire --- app/javascript/flavours/glitch/actions/notifications.js | 5 +++++ app/javascript/flavours/glitch/main.jsx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/javascript/flavours/glitch/actions/notifications.js b/app/javascript/flavours/glitch/actions/notifications.js index a80746b756..81b8045d70 100644 --- a/app/javascript/flavours/glitch/actions/notifications.js +++ b/app/javascript/flavours/glitch/actions/notifications.js @@ -18,6 +18,7 @@ import { importFetchedStatuses, } from './importer'; import { submitMarkers } from './markers'; +import { register as registerPushNotifications } from './push_notifications'; import { saveSettings } from './settings'; @@ -384,6 +385,10 @@ export function requestBrowserPermission(callback = noOp) { requestNotificationPermission((permission) => { dispatch(setBrowserPermission(permission)); callback(permission); + + if (permission === 'granted') { + dispatch(registerPushNotifications()); + } }); }; } diff --git a/app/javascript/flavours/glitch/main.jsx b/app/javascript/flavours/glitch/main.jsx index b1a3c249bf..2aef67fa3a 100644 --- a/app/javascript/flavours/glitch/main.jsx +++ b/app/javascript/flavours/glitch/main.jsx @@ -33,7 +33,7 @@ function main() { console.error(err); } - if (registration) { + if (registration && 'Notification' in window && Notification.permission === 'granted') { const registerPushNotifications = await import('flavours/glitch/actions/push_notifications'); store.dispatch(registerPushNotifications.register());