Fix Messenger when Notification not supported in browser.
Ylian Saint-Hilaire committed
Jun 1, 2021 at 22:54 UTC
cd7443fe9890b826dc2a14da0a854d93307ef1ef
1 file changed
+27
-14
views/messenger.handlebars
+27
-14
@@ -90,6 +90,7 @@
90
var remoteOutText = false;
91
var remoteImage = false;
92
var serverRecording = false;
93
+ var notificationSupport = true;
94
95
// File transfer state
96
var fileUploads = [];
@@ -120,7 +121,7 @@
121
QH('xtitle', EscapeHtml(newTitle).split(' ').join(' '));
122
123
// Setup web notifications
123
- try { if (Notification) { QV('notifyButton', Notification.permission != 'granted'); } } catch (ex) { }
124
+ try { if (Notification) { QV('notifyButton', Notification.permission != 'granted'); } } catch (ex) { notificationSupport = false; }
125
126
// Track window focus
127
window.addEventListener('focus', function (event) { windowFocus = true; }, false);
@@ -132,14 +133,18 @@
133
document.addEventListener('drop', fileDrop, false);
134
135
document.onclick = function (e) {
135
- if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
136
- if (notification != null) { notification.close(); notification = null; }
136
+ if (notificationSupport) {
137
+ if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
138
+ if (notification != null) { notification.close(); notification = null; }
139
+ }
140
}
141
142
// Trap document key up events
143
document.onkeyup = function ondockeypress(e) {
141
- if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
142
- if (notification != null) { notification.close(); notification = null; }
144
+ if (notificationSupport) {
145
+ if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
146
+ if (notification != null) { notification.close(); notification = null; }
147
+ }
148
if (state == 2) {
149
if ((e.keyCode == 8) && (userInputFocus == 0)) {
150
// Backspace
@@ -153,8 +158,10 @@
158
159
// Trap document key presses
160
document.onkeypress = function ondockeypress(e) {
156
- if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
157
- if (notification != null) { notification.close(); notification = null; }
161
+ if (notificationSupport) {
162
+ if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
163
+ if (notification != null) { notification.close(); notification = null; }
164
+ }
165
if ((state == 2) || pushMessaging) {
166
if (e.keyCode == 13) {
167
// Return
@@ -227,17 +234,21 @@
234
Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
235
236
// If web notifications are granted, use it.
230
- if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
231
- if (Notification && (windowFocus == false) && (Notification.permission == 'granted')) {
232
- if (notification != null) { notification.close(); notification = null; }
233
- notification = new Notification(Q('xtitle').innerHTML.split(' ').join(' '), { body: msg });
237
+ if (notificationSupport) {
238
+ if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
239
+ if (Notification && (windowFocus == false) && (Notification.permission == 'granted')) {
240
+ if (notification != null) { notification.close(); notification = null; }
241
+ notification = new Notification(Q('xtitle').innerHTML.split(' ').join(' '), { body: msg });
242
+ }
243
}
244
}
245
246
// Display and send a message from the local user
247
function xsend(event) {
239
- if (notification != null) { notification.close(); notification = null; }
240
- if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
248
+ if (notificationSupport) {
249
+ if (notification != null) { notification.close(); notification = null; }
250
+ if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
251
+ }
252
var outtext = Q('xouttext').value;
253
if (outtext.length > 0) {
254
chatTextSession += ((new Date()).toLocaleTimeString() + ' - ' + "Local" + '> ' + outtext + '\r\n');
@@ -623,7 +634,9 @@
634
635
// Toggle notification
636
function enableNotificationsButtonClick() {
626
- if (Notification) { Notification.requestPermission().then(function (permission) { QV('notifyButton', permission != 'granted'); }); }
637
+ if (notificationSupport) {
638
+ if (Notification) { Notification.requestPermission().then(function (permission) { QV('notifyButton', permission != 'granted'); }); }
639
+ }
640
return false;
641
}
642