mirror of
https://github.com/discourse/discourse.git
synced 2025-03-25 17:36:53 +08:00
FIX: allow chat sound when notifications are disabled (#28385)
Desktop chat notification sounds have stopped working on most desktop browsers. This is due to Notifications API being disabled when Push Notifications are supported in the browser, which means that we never iterate on the desktopNotificationHandlers and trigger the callback since we return early.
This commit is contained in:
parent
e16f22c372
commit
de08ce8f7b
@ -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 bus
|
||||
async function onNotification(data, siteSettings, user, appEvents) {
|
||||
if (!canUserReceiveNotifications(user)) {
|
||||
return false;
|
||||
}
|
||||
const showNotifications = canUserReceiveNotifications(user) && liveEnabled;
|
||||
|
||||
if (!liveEnabled) {
|
||||
return false;
|
||||
}
|
||||
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 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 notificationTag =
|
||||
"discourse-notification-" +
|
||||
siteSettings.title +
|
||||
"-" +
|
||||
(data.topic_id || 0);
|
||||
|
||||
await requestPermission();
|
||||
|
||||
const notification = new Notification(notificationTitle, {
|
||||
body: data.excerpt,
|
||||
icon: notificationIcon,
|
||||
tag: notificationTag,
|
||||
});
|
||||
|
||||
const notificationBody = data.excerpt;
|
||||
|
||||
const notificationIcon =
|
||||
siteSettings.site_logo_small_url || siteSettings.site_logo_url;
|
||||
|
||||
const notificationTag =
|
||||
"discourse-notification-" + siteSettings.title + "-" + (data.topic_id || 0);
|
||||
|
||||
await requestPermission();
|
||||
|
||||
// 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user