0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-18 07:52:03 +01:00

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 <art27@cantab.net>

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
zeripath 2020-07-04 15:01:25 +01:00 committed by GitHub
parent 510e4bd245
commit 60cb9fe448
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 17 deletions

View file

@ -87,7 +87,7 @@ self.onconnect = (e) => {
// How this has happened I don't understand... // How this has happened I don't understand...
// deregister from that source // deregister from that source
const count = source.deregister(port); const count = source.deregister(port);
// Clean-up // Clean-up
if (count === 0) { if (count === 0) {
source.close(); source.close();
sourcesByUrl[source.url] = null; sourcesByUrl[source.url] = null;
@ -98,11 +98,9 @@ self.onconnect = (e) => {
source.register(port); source.register(port);
sourcesByUrl[url] = source; sourcesByUrl[url] = source;
sourcesByPort[port] = source; sourcesByPort[port] = source;
return;
} else if (event.data.type === 'listen') { } else if (event.data.type === 'listen') {
const source = sourcesByPort[port]; const source = sourcesByPort[port];
source.listen(event.data.eventType); source.listen(event.data.eventType);
return;
} else if (event.data.type === 'close') { } else if (event.data.type === 'close') {
const source = sourcesByPort[port]; const source = sourcesByPort[port];
@ -114,7 +112,6 @@ self.onconnect = (e) => {
sourcesByUrl[source.url] = null; sourcesByUrl[source.url] = null;
sourcesByPort[port] = null; sourcesByPort[port] = null;
} }
return;
} else if (event.data.type === 'status') { } else if (event.data.type === 'status') {
const source = sourcesByPort[port]; const source = sourcesByPort[port];
if (!source) { if (!source) {
@ -125,14 +122,12 @@ self.onconnect = (e) => {
return; return;
} }
source.status(port); source.status(port);
return;
} else { } else {
// just send it back // just send it back
port.postMessage({ port.postMessage({
type: 'error', type: 'error',
message: `received but don't know how to handle: ${event.data}`, message: `received but don't know how to handle: ${event.data}`,
}); });
return;
} }
}); });
port.start(); port.start();

View file

@ -57,19 +57,17 @@ export async function initNotificationCount() {
type: 'start', type: 'start',
url: `${window.location.origin}${AppSubUrl}/user/events`, url: `${window.location.origin}${AppSubUrl}/user/events`,
}); });
worker.port.addEventListener('message', (e) => { worker.port.addEventListener('message', (event) => {
if (!e.data || !e.data.type) { if (!event.data || !event.data.type) {
console.error(e); console.error(event);
return; return;
} }
if (event.data.type === 'notification-count') { if (event.data.type === 'notification-count') {
receiveUpdateCount(e.data); receiveUpdateCount(event.data);
return;
} else if (event.data.type === 'error') { } else if (event.data.type === 'error') {
console.error(e.data); console.error(event.data);
return;
} else if (event.data.type === 'logout') { } else if (event.data.type === 'logout') {
if (e.data !== 'here') { if (event.data !== 'here') {
return; return;
} }
worker.port.postMessage({ worker.port.postMessage({
@ -77,9 +75,6 @@ export async function initNotificationCount() {
}); });
worker.port.close(); worker.port.close();
window.location.href = AppSubUrl; window.location.href = AppSubUrl;
return;
} else {
return;
} }
}); });
worker.port.addEventListener('error', (e) => { worker.port.addEventListener('error', (e) => {