@@ -32,6 +32,10 @@ const owNotificationWindow = {
32
32
// closing the window
33
33
$ ( window ) . on ( "beforeunload" , function ( ) {
34
34
owNotificationWindow . remove ( ) ;
35
+ // Disconnect websocket to prevent missed notifications during page reload
36
+ if ( typeof notificationSocket !== "undefined" ) {
37
+ notificationSocket . close ( ) ;
38
+ }
35
39
} ) ;
36
40
// Get authority to play notification sound when
37
41
// other windows are closed
@@ -160,7 +164,9 @@ function notificationWidget($) {
160
164
}
161
165
162
166
function appendPage ( ) {
163
- $ ( "#ow-notifications-loader" ) . before ( pageContainer ( fetchedPages [ lastRenderedPage ] ) ) ;
167
+ $ ( "#ow-notifications-loader" ) . before (
168
+ pageContainer ( fetchedPages [ lastRenderedPage ] ) ,
169
+ ) ;
164
170
if ( lastRenderedPage >= renderedPages ) {
165
171
$ ( ".ow-notification-wrapper div:first" ) . remove ( ) ;
166
172
}
@@ -185,7 +191,10 @@ function notificationWidget($) {
185
191
} ,
186
192
success : function ( res ) {
187
193
nextPageUrl = res . next ;
188
- if ( res . count === 0 || ( res . results . length === 0 && nextPageUrl === null ) ) {
194
+ if (
195
+ res . count === 0 ||
196
+ ( res . results . length === 0 && nextPageUrl === null )
197
+ ) {
189
198
// If response does not have any notification, show no-notifications message.
190
199
$ ( ".ow-no-notifications" ) . removeClass ( "ow-hide" ) ;
191
200
$ ( "#ow-mark-all-read" ) . addClass ( "disabled" ) ;
@@ -225,7 +234,9 @@ function notificationWidget($) {
225
234
busy = true ;
226
235
if ( lastRenderedPage > renderedPages ) {
227
236
$ ( ".ow-notification-wrapper div.page:last" ) . remove ( ) ;
228
- var addedDiv = pageContainer ( fetchedPages [ lastRenderedPage - renderedPages - 1 ] ) ;
237
+ var addedDiv = pageContainer (
238
+ fetchedPages [ lastRenderedPage - renderedPages - 1 ] ,
239
+ ) ;
229
240
$ ( ".ow-notification-wrapper" ) . prepend ( addedDiv ) ;
230
241
lastRenderedPage -= 1 ;
231
242
}
@@ -247,7 +258,9 @@ function notificationWidget($) {
247
258
248
259
function notificationListItem ( elem ) {
249
260
let klass ;
250
- const datetime = dateTimeStampToDateTimeLocaleString ( new Date ( elem . timestamp ) ) ;
261
+ const datetime = dateTimeStampToDateTimeLocaleString (
262
+ new Date ( elem . timestamp ) ,
263
+ ) ;
251
264
252
265
if ( ! notificationReadStatus . has ( elem . id ) ) {
253
266
if ( elem . unread ) {
@@ -408,7 +421,9 @@ function markNotificationRead(elem) {
408
421
function notificationHandler ( $ , elem ) {
409
422
var notification = fetchedPages
410
423
. flat ( )
411
- . find ( ( notification ) => notification . id == elem . get ( 0 ) . id . replace ( "ow-" , "" ) ) ,
424
+ . find (
425
+ ( notification ) => notification . id == elem . get ( 0 ) . id . replace ( "ow-" , "" ) ,
426
+ ) ,
412
427
targetUrl = elem . data ( "location" ) ;
413
428
414
429
// If notification is unread then send read request
@@ -433,7 +448,9 @@ function notificationHandler($, elem) {
433
448
</div>
434
449
<div class="ow-notification-date">${ datetime } </div>
435
450
` ) ;
436
- $ ( ".ow-message-title" ) . html ( convertMessageWithRelativeURL ( notification . message ) ) ;
451
+ $ ( ".ow-message-title" ) . html (
452
+ convertMessageWithRelativeURL ( notification . message ) ,
453
+ ) ;
437
454
$ ( ".ow-message-description" ) . html ( notification . description ) ;
438
455
$ ( ".ow-overlay-notification" ) . removeClass ( "ow-hide" ) ;
439
456
@@ -473,7 +490,8 @@ function initWebSockets($) {
473
490
}
474
491
// Check whether to display notification toast
475
492
if ( data . notification ) {
476
- let toast = $ ( `<div class="ow-notification-toast ${ data . notification . level } "
493
+ let toast =
494
+ $ ( `<div class="ow-notification-toast ${ data . notification . level } "
477
495
data-location="${ convertAbsoluteURLToRelativeURL ( data . notification . target_url ) } "
478
496
id="ow-${ data . notification . id } ">
479
497
<div class="icon ow-notify-close btn" role="button" tabindex="1"></div>
0 commit comments