Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notification permissions being requested immediately after login #26472

Merged
merged 1 commit into from Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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