From bbb40aef5125d5ff2751337d0f1b8b06d7f0a660 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sun, 16 Jun 2019 18:11:34 -0500 Subject: [PATCH] Fix event listener for notifications.js --- assets/js/notifications.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/assets/js/notifications.js b/assets/js/notifications.js index 941ad9a0..2ba0bbcc 100644 --- a/assets/js/notifications.js +++ b/assets/js/notifications.js @@ -45,7 +45,7 @@ function create_notification_stream(subscriptions) { notifications.onmessage = function (event) { if (!event.id) { - return + return; } var notification = JSON.parse(event.data); @@ -80,15 +80,16 @@ function create_notification_stream(subscriptions) { } } - notifications.onerror = function (event) { - console.log('Something went wrong with notifications, trying to reconnect...'); - notifications = { close: function () { } }; - setTimeout(function () { get_subscriptions(create_notification_stream) }, 1000); - } - + notifications.addEventListener('error', handle_notification_error); notifications.stream(); } +function handle_notification_error(event) { + console.log('Something went wrong with notifications, trying to reconnect...'); + notifications = { close: function () { } }; + setTimeout(function () { get_subscriptions(create_notification_stream) }, 1000); +} + window.addEventListener('load', function (e) { localStorage.setItem('notification_count', document.getElementById('notification_count') ? document.getElementById('notification_count').innerText : '0');