From 60cb9fe44878f31e40bac7a9b64a77a9cffdc9f6 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sat, 4 Jul 2020 15:01:25 +0100 Subject: [PATCH] Bugfix for shared event source (#12129) For some reason our eslint configuration is not working correctly and a bug has become apparent when trying to backport this to 1.12. Signed-off-by: Andrew Thornton Co-authored-by: techknowlogick --- web_src/js/features/eventsource.sharedworker.js | 7 +------ web_src/js/features/notification.js | 17 ++++++----------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/web_src/js/features/eventsource.sharedworker.js b/web_src/js/features/eventsource.sharedworker.js index 7dccd8994e1..e3c60ce0db1 100644 --- a/web_src/js/features/eventsource.sharedworker.js +++ b/web_src/js/features/eventsource.sharedworker.js @@ -87,7 +87,7 @@ self.onconnect = (e) => { // How this has happened I don't understand... // deregister from that source const count = source.deregister(port); - // Clean-up + // Clean-up if (count === 0) { source.close(); sourcesByUrl[source.url] = null; @@ -98,11 +98,9 @@ self.onconnect = (e) => { source.register(port); sourcesByUrl[url] = source; sourcesByPort[port] = source; - return; } else if (event.data.type === 'listen') { const source = sourcesByPort[port]; source.listen(event.data.eventType); - return; } else if (event.data.type === 'close') { const source = sourcesByPort[port]; @@ -114,7 +112,6 @@ self.onconnect = (e) => { sourcesByUrl[source.url] = null; sourcesByPort[port] = null; } - return; } else if (event.data.type === 'status') { const source = sourcesByPort[port]; if (!source) { @@ -125,14 +122,12 @@ self.onconnect = (e) => { return; } source.status(port); - return; } else { // just send it back port.postMessage({ type: 'error', message: `received but don't know how to handle: ${event.data}`, }); - return; } }); port.start(); diff --git a/web_src/js/features/notification.js b/web_src/js/features/notification.js index 2b7fc452374..aa1b48d1837 100644 --- a/web_src/js/features/notification.js +++ b/web_src/js/features/notification.js @@ -57,19 +57,17 @@ export async function initNotificationCount() { type: 'start', url: `${window.location.origin}${AppSubUrl}/user/events`, }); - worker.port.addEventListener('message', (e) => { - if (!e.data || !e.data.type) { - console.error(e); + worker.port.addEventListener('message', (event) => { + if (!event.data || !event.data.type) { + console.error(event); return; } if (event.data.type === 'notification-count') { - receiveUpdateCount(e.data); - return; + receiveUpdateCount(event.data); } else if (event.data.type === 'error') { - console.error(e.data); - return; + console.error(event.data); } else if (event.data.type === 'logout') { - if (e.data !== 'here') { + if (event.data !== 'here') { return; } worker.port.postMessage({ @@ -77,9 +75,6 @@ export async function initNotificationCount() { }); worker.port.close(); window.location.href = AppSubUrl; - return; - } else { - return; } }); worker.port.addEventListener('error', (e) => {