Browse Source

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>
tags/v1.13.0-rc1
zeripath 3 years ago
parent
commit
60cb9fe448
No account linked to committer's email address

+ 1
- 6
web_src/js/features/eventsource.sharedworker.js View File

// 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;
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];


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) {
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();

+ 6
- 11
web_src/js/features/notification.js View File

type: 'start', type: 'start',
url: `${window.location.origin}${AppSubUrl}/user/events`, 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; return;
} }
if (event.data.type === 'notification-count') { if (event.data.type === 'notification-count') {
receiveUpdateCount(e.data);
return;
receiveUpdateCount(event.data);
} else if (event.data.type === 'error') { } else if (event.data.type === 'error') {
console.error(e.data);
return;
console.error(event.data);
} 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({
}); });
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) => {

Loading…
Cancel
Save