Skip to content

Commit

Permalink
Fix notification permissions being requested immediately after login (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and vmstan committed Jan 5, 2024
1 parent 1fa0ff4 commit 37e3116
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/javascript/mastodon/actions/notifications.js
Expand Up @@ -18,6 +18,7 @@ import {
importFetchedStatuses,
} from './importer';
import { submitMarkers } from './markers';
import { register as registerPushNotifications } from './push_notifications';
import { saveSettings } from './settings';

export const NOTIFICATIONS_UPDATE = 'NOTIFICATIONS_UPDATE';
Expand Down Expand Up @@ -293,6 +294,10 @@ export function requestBrowserPermission(callback = noOp) {
requestNotificationPermission((permission) => {
dispatch(setBrowserPermission(permission));
callback(permission);

if (permission === 'granted') {
dispatch(registerPushNotifications());
}
});
};
}
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/main.jsx
Expand Up @@ -33,7 +33,7 @@ function main() {
console.error(err);
}

if (registration) {
if (registration && 'Notification' in window && Notification.permission === 'granted') {
const registerPushNotifications = await import('mastodon/actions/push_notifications');

store.dispatch(registerPushNotifications.register());
Expand Down

0 comments on commit 37e3116

Please sign in to comment.