Skip to content

Commit

Permalink
fix messenger background notifications #2440
Browse files Browse the repository at this point in the history
Signed-off-by: si458 <[email protected]>
  • Loading branch information
si458 committed Dec 1, 2024
1 parent d9262f7 commit ce4217c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions views/messenger.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
var remoteUserId = '{{{userid}}}';
var webrtcconfiguration = '{{{webrtcconfig}}}';
if (webrtcconfiguration == '') { webrtcconfiguration = null; } else { try { webrtcconfiguration = JSON.parse(decodeURIComponent(webrtcconfiguration)); } catch (ex) { console.log('Invalid WebRTC config: "' + webrtcconfiguration + '".'); webrtcconfiguration = null; } }
var windowFocus = true;
var chatTextSession = new Date().toString() + '\r\n';
var localOutText = false;
var remoteOutText = false;
Expand Down Expand Up @@ -124,10 +123,6 @@
// Setup web notifications
try { if (Notification) { QV('notifyButton', Notification.permission != 'granted'); } } catch (ex) { notificationSupport = false; }
// Track window focus
window.addEventListener('focus', function (event) { windowFocus = true; }, false);
window.addEventListener('blur', function (event) { windowFocus = false; }, false);
// Listen to drag & drop events
document.addEventListener('dragover', haltEvent, false);
document.addEventListener('dragleave', haltEvent, false);
Expand Down Expand Up @@ -237,9 +232,14 @@
// If web notifications are granted, use it.
if (notificationSupport) {
if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
if (Notification && (windowFocus == false) && (Notification.permission == 'granted')) {
if (Notification && (document.visibilityState === 'hidden') && (Notification.permission == 'granted')) {
if (notification != null) { notification.close(); notification = null; }
notification = new Notification(Q('xtitle').innerHTML.split('&nbsp;').join(' '), { body: msg });
notification.onclick = function(event) {
event.preventDefault();
if (document.visibilityState === 'hidden') window.focus();
notification.close();
};
}
}
}
Expand Down

0 comments on commit ce4217c

Please sign in to comment.