mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
Suggested changes
This commit is contained in:
parent
a616d9ed1c
commit
21b915f209
3 changed files with 19 additions and 29 deletions
|
@ -1,7 +1,5 @@
|
||||||
const NotificationsController = Ember.ArrayController.extend({
|
export default Ember.ArrayController.extend({
|
||||||
needs: ['header'],
|
needs: ['header'],
|
||||||
loadingNotifications: Em.computed.alias('controllers.header.loadingNotifications'),
|
loadingNotifications: Em.computed.alias('controllers.header.loadingNotifications'),
|
||||||
myNotificationsUrl: Discourse.computed.url('/my/notifications')
|
myNotificationsUrl: Discourse.computed.url('/my/notifications')
|
||||||
});
|
});
|
||||||
|
|
||||||
export default NotificationsController;
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ export default {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
initDesktopNotifications(container);
|
initDesktopNotifications(bus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,35 +1,34 @@
|
||||||
|
|
||||||
let primaryTab;
|
let primaryTab = false;
|
||||||
let liveEnabled;
|
let liveEnabled = false;
|
||||||
let notificationTagName;
|
let mbClientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
|
||||||
let mbClientId;
|
let lastAction = -1;
|
||||||
let lastAction;
|
|
||||||
|
|
||||||
const focusTrackerKey = "focus-tracker";
|
const focusTrackerKey = "focus-tracker";
|
||||||
const seenDataKey = "seen-notifications";
|
const seenDataKey = "seen-notifications";
|
||||||
const recentUpdateThreshold = 1000 * 60 * 2; // 2 minutes
|
const recentUpdateThreshold = 1000 * 60 * 2; // 2 minutes
|
||||||
const idleThresholdTime = 1000 * 10; // 10 seconds
|
const idleThresholdTime = 1000 * 10; // 10 seconds
|
||||||
const INVITED_TYPE = 8;
|
const INVITED_TYPE = 8;
|
||||||
|
let notificationTagName; // "discourse-notification-popup-" + Discourse.SiteSettings.title;
|
||||||
|
|
||||||
function init(container) {
|
// Called from an initializer
|
||||||
|
function init(messageBus) {
|
||||||
liveEnabled = false;
|
liveEnabled = false;
|
||||||
|
mbClientId = messageBus.clientId;
|
||||||
requestPermission().then(function() {
|
requestPermission().then(function() {
|
||||||
try {
|
try {
|
||||||
localStorage.getItem(focusTrackerKey);
|
localStorage.getItem(focusTrackerKey);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Em.Logger.info('Discourse desktop notifications are disabled - localStorage denied.');
|
Em.Logger.info('Discourse desktop notifications are disabled - localStorage denied.');
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
liveEnabled = true;
|
liveEnabled = true;
|
||||||
Em.Logger.info('Discourse desktop notifications are enabled.');
|
Em.Logger.info('Discourse desktop notifications are enabled.');
|
||||||
return true;
|
try {
|
||||||
}).then(function(c) {
|
// Permission is granted, continue with setup
|
||||||
if (c) {
|
setupNotifications();
|
||||||
try {
|
} catch (e) {
|
||||||
init2(container);
|
Em.Logger.error(e);
|
||||||
} catch (e) {
|
|
||||||
Em.Logger.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}).catch(function() {
|
}).catch(function() {
|
||||||
liveEnabled = false;
|
liveEnabled = false;
|
||||||
|
@ -37,7 +36,8 @@ function init(container) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function init2(container) {
|
// This function is only called if permission was granted
|
||||||
|
function setupNotifications() {
|
||||||
// Load up the current state of the notifications
|
// Load up the current state of the notifications
|
||||||
const seenData = JSON.parse(localStorage.getItem(seenDataKey));
|
const seenData = JSON.parse(localStorage.getItem(seenDataKey));
|
||||||
let markAllSeen = true;
|
let markAllSeen = true;
|
||||||
|
@ -59,8 +59,6 @@ function init2(container) {
|
||||||
|
|
||||||
notificationTagName = "discourse-notification-popup-" + Discourse.SiteSettings.title;
|
notificationTagName = "discourse-notification-popup-" + Discourse.SiteSettings.title;
|
||||||
|
|
||||||
const messageBus = container.lookup('message-bus:main');
|
|
||||||
mbClientId = messageBus.clientId;
|
|
||||||
|
|
||||||
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()
|
||||||
|
@ -68,9 +66,7 @@ function init2(container) {
|
||||||
if (key !== focusTrackerKey) {
|
if (key !== focusTrackerKey) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (primaryTab) {
|
primaryTab = false;
|
||||||
primaryTab = false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener("focus", function() {
|
window.addEventListener("focus", function() {
|
||||||
|
@ -150,10 +146,6 @@ function onNotification(currentUser) {
|
||||||
tag: notificationTagName
|
tag: notificationTagName
|
||||||
});
|
});
|
||||||
|
|
||||||
// if (enableSound) {
|
|
||||||
// soundElement.play();
|
|
||||||
// }
|
|
||||||
|
|
||||||
const firstUnseen = unseen[0];
|
const firstUnseen = unseen[0];
|
||||||
|
|
||||||
function clickEventHandler() {
|
function clickEventHandler() {
|
||||||
|
|
Loading…
Reference in a new issue