From 7e04b15ad8bde9b22e7a3bb717e3d6177d3fa430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elizabeth=20Mart=C3=ADn=20Campos?= Date: Fri, 3 Feb 2023 09:29:32 +0100 Subject: [PATCH] fix(web-push-notifications): fix favourite push notifications (#23286) Fix a bug where clicking in a favourite push notification would result in a 404 (not found) error, since we were redirecting the user to the wrong URL (we were redirecting to /@/, when it should be /@/) --- .../mastodon/service_worker/web_push_notifications.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/javascript/mastodon/service_worker/web_push_notifications.js b/app/javascript/mastodon/service_worker/web_push_notifications.js index f12595777..b9d626694 100644 --- a/app/javascript/mastodon/service_worker/web_push_notifications.js +++ b/app/javascript/mastodon/service_worker/web_push_notifications.js @@ -1,6 +1,6 @@ import IntlMessageFormat from 'intl-messageformat'; -import locales from './web_push_locales'; import { unescape } from 'lodash'; +import locales from './web_push_locales'; const MAX_NOTIFICATIONS = 5; const GROUP_TAG = 'tag'; @@ -90,7 +90,13 @@ export const handlePush = (event) => { options.tag = notification.id; options.badge = '/badge.png'; options.image = notification.status && notification.status.media_attachments.length > 0 && notification.status.media_attachments[0].preview_url || undefined; - options.data = { access_token, preferred_locale, id: notification.status ? notification.status.id : notification.account.id, url: notification.status ? `/@${notification.account.acct}/${notification.status.id}` : `/@${notification.account.acct}` }; + options.data = { access_token, preferred_locale, id: notification.status ? notification.status.id : notification.account.id }; + + if (notification.status) { + options.data.url = `/@${notification.status.account.acct}/${notification.status.id}`; + } else { + options.data.url = `/@${notification.account.acct}`; + } if (notification.status && notification.status.spoiler_text || notification.status.sensitive) { options.data.hiddenBody = htmlToPlainText(notification.status.content);