Merge pull request #3465 from riking/patch-2

FEATURE: Multiple notifications at once (1/topic)
This commit is contained in:
Régis Hanol 2015-05-14 10:05:48 +02:00
commit 0b62730382
2 changed files with 3 additions and 6 deletions

View File

@ -7,7 +7,6 @@ let lastAction = -1;
const focusTrackerKey = "focus-tracker"; const focusTrackerKey = "focus-tracker";
const idleThresholdTime = 1000 * 10; // 10 seconds const idleThresholdTime = 1000 * 10; // 10 seconds
let notificationTagName; // "discourse-notification-popup-" + Discourse.SiteSettings.title;
// Called from an initializer // Called from an initializer
function init(messageBus) { function init(messageBus) {
@ -25,8 +24,6 @@ function init(messageBus) {
return; return;
} }
if (!("Notification" in window)) { if (!("Notification" in window)) {
Em.Logger.info('Discourse desktop notifications are disabled - not supported by browser'); Em.Logger.info('Discourse desktop notifications are disabled - not supported by browser');
return; return;
@ -55,8 +52,6 @@ function init(messageBus) {
// This function is only called if permission was granted // This function is only called if permission was granted
function setupNotifications() { function setupNotifications() {
notificationTagName = "discourse-notification-popup-" + Discourse.SiteSettings.title;
window.addEventListener("storage", function(e) { window.addEventListener("storage", function(e) {
// note: This event only fires when other tabs setItem() // note: This event only fires when other tabs setItem()
const key = e.key; const key = e.key;
@ -108,13 +103,14 @@ function onNotification(data) {
const notificationBody = data.excerpt; const notificationBody = data.excerpt;
const notificationIcon = Discourse.SiteSettings.logo_small_url || Discourse.SiteSettings.logo_url; const notificationIcon = Discourse.SiteSettings.logo_small_url || Discourse.SiteSettings.logo_url;
const notificationTag = "discourse-notification-" + Discourse.SiteSettings.title + "-" + data.topic_id;
requestPermission().then(function() { requestPermission().then(function() {
// This shows the notification! // This shows the notification!
const notification = new Notification(notificationTitle, { const notification = new Notification(notificationTitle, {
body: notificationBody, body: notificationBody,
icon: notificationIcon, icon: notificationIcon,
tag: notificationTagName tag: notificationTag
}); });
function clickEventHandler() { function clickEventHandler() {

View File

@ -157,6 +157,7 @@ class PostAlerter
notification_type: type, notification_type: type,
post_number: original_post.post_number, post_number: original_post.post_number,
topic_title: original_post.topic.title, topic_title: original_post.topic.title,
topic_id: original_post.topic.id,
excerpt: original_post.excerpt(400, text_entities: true, strip_links: true), excerpt: original_post.excerpt(400, text_entities: true, strip_links: true),
username: original_username, username: original_username,
post_url: post_url post_url: post_url