A platform for community discussion. Free, open, simple.
FIX: allow chat sound when notifications are disabled (#28385)
David Battersbyde08ce8f7b2d
diff --git a/app/assets/javascripts/discourse/app/lib/desktop-notifications.js b/app/assets/javascripts/discourse/app/lib/desktop-notifications.jsindex c3b6ffc86f4..fdfff4e07f8 100644--- a/app/assets/javascripts/discourse/app/lib/desktop-notifications.js+++ b/app/assets/javascripts/discourse/app/lib/desktop-notifications.js@@ -135,7 +135,7 @@ function canUserReceiveNotifications(user) {return false;}- if (keyValueStore.getItem("notifications-disabled", "disabled")) {+ if (keyValueStore.getItem("notifications-disabled") === "disabled") {return false;}@@ -144,44 +144,46 @@ function canUserReceiveNotifications(user) {// Call-in point from message busasync function onNotification(data, siteSettings, user, appEvents) {- if (!canUserReceiveNotifications(user)) {- return false;- }-- if (!liveEnabled) {- return false;- }-- const notificationTitle =- data.translated_title ||- I18n.t(i18nKey(data.notification_type), {- site_title: siteSettings.title,- topic: data.topic_title,- username: formatUsername(data.username),- group_name: data.group_name,- });-- const notificationBody = data.excerpt;+ const showNotifications = canUserReceiveNotifications(user) && liveEnabled;++ if (showNotifications) {+ const notificationTitle =+ data.translated_title ||+ I18n.t(i18nKey(data.notification_type), {+ site_title: siteSettings.title,+ topic: data.topic_title,+ username: formatUsername(data.username),+ group_name: data.group_name,+ });- const notificationIcon =- siteSettings.site_logo_small_url || siteSettings.site_logo_url;+ const notificationIcon =+ siteSettings.site_logo_small_url || siteSettings.site_logo_url;+ const notificationTag =+ "discourse-notification-" ++ siteSettings.title ++ "-" ++ (data.topic_id || 0);- const notificationTag =- "discourse-notification-" + siteSettings.title + "-" + (data.topic_id || 0);+ await requestPermission();- await requestPermission();+ const notification = new Notification(notificationTitle, {+ body: data.excerpt,+ icon: notificationIcon,+ tag: notificationTag,+ });- // This shows the notification!- const notification = new Notification(notificationTitle, {- body: notificationBody,- icon: notificationIcon,- tag: notificationTag,- });- notification.onclick = () => {- DiscourseURL.routeTo(data.post_url);- appEvents.trigger("desktop-notification-opened", { url: data.post_url });- notification.close();- };+ notification.addEventListener(+ "click",+ () => {+ DiscourseURL.routeTo(data.post_url);+ appEvents.trigger("desktop-notification-opened", {+ url: data.post_url,+ });+ notification.close();+ },+ { once: true }+ );+ }desktopNotificationHandlers.forEach((handler) =>handler(data, siteSettings, user)