Skip to content
Snippets Groups Projects
Commit a22364e4 authored by echicken's avatar echicken :chicken:
Browse files

Allow additional parameters in call to events.ssjs.

Return-style load of web/lib/auth.ssjs.
parent 7c501958
No related branches found
No related tags found
No related merge requests found
load('sbbsdefs.js'); load('sbbsdefs.js');
load('modopts.js'); load('modopts.js');
var settings = get_mod_options('web'); const settings = get_mod_options('web');
load(settings.web_directory + '/lib/init.js'); load(settings.web_directory + '/lib/init.js');
load(settings.web_lib + 'auth.js'); const auth_lib = load({}, settings.web_lib + 'auth.js');
http_reply.header['Cache-Control'] = 'no-cache'; http_reply.header['Cache-Control'] = 'no-cache';
http_reply.header['Content-type'] = 'text/event-stream'; http_reply.header['Content-type'] = 'text/event-stream';
......
...@@ -59,6 +59,17 @@ function sendTelegram(alias) { ...@@ -59,6 +59,17 @@ function sendTelegram(alias) {
$('#popUpModal').modal('show'); $('#popUpModal').modal('show');
} }
function registerEventListener(scope, callback, params) {
params = Object.keys(params || {}).reduce(function (a, c) {
a += '&' + c + '=' + params[c];
return a;
}, '');
_sbbs_events[scope] = {
qs: 'subscribe=' + scope + params,
callback: callback
};
}
window.onload = function () { window.onload = function () {
$('#button-logout').click(logout); $('#button-logout').click(logout);
...@@ -79,14 +90,14 @@ window.onload = function () { ...@@ -79,14 +90,14 @@ window.onload = function () {
if ($('#button-logout').length > 0) { if ($('#button-logout').length > 0) {
_sbbs_events.mail = function (e) { registerEventListener('mail', function (e) {
const data = JSON.parse(e.data); const data = JSON.parse(e.data);
if (typeof data.count != 'number') return; if (typeof data.count != 'number') return;
$('#badge-unread-mail').text(data.count < 1 ? '' : data.count); $('#badge-unread-mail').text(data.count < 1 ? '' : data.count);
$('#badge-unread-mail-inner').text(data.count < 1 ? '' : data.count); $('#badge-unread-mail-inner').text(data.count < 1 ? '' : data.count);
} });
_sbbs_events.telegram = function (e) { registerEventListener('telegram', function (e) {
const tg = JSON.parse(e.data).replace(/\1./g, '').replace( const tg = JSON.parse(e.data).replace(/\1./g, '').replace(
/\r?\n/g, '<br>' /\r?\n/g, '<br>'
); );
...@@ -94,16 +105,17 @@ window.onload = function () { ...@@ -94,16 +105,17 @@ window.onload = function () {
$('#popUpModalBody').append(tg); $('#popUpModalBody').append(tg);
$('#popUpModalActionButton').hide(); $('#popUpModalActionButton').hide();
$('#popUpModal').modal('show'); $('#popUpModal').modal('show');
} });
} }
const _evtqs = Object.keys(_sbbs_events).reduce(function (a, c, i) { const qs = Object.keys(_sbbs_events).reduce(function (a, c, i) {
return a + (i == 0 ? '?' : '&') + 'subscribe=' + c; }, '' return a + (i == 0 ? '?' : '&') + _sbbs_events[c].qs;
); }, '');
const _es = new EventSource('/api/events.ssjs' + _evtqs);
const es = new EventSource('/api/events.ssjs' + qs);
Object.keys(_sbbs_events).forEach(function (e) { Object.keys(_sbbs_events).forEach(function (e) {
_es.addEventListener(e, _sbbs_events[e]); es.addEventListener(e, _sbbs_events[e].callback);
}); });
} }
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
$('#sidebar').find('.sb-nodes-available').text(nll - niu); $('#sidebar').find('.sb-nodes-available').text(nll - niu);
} }
_sbbs_events.nodelist = _sb_nodelist; registerEventListener('nodelist', _sb_nodelist);
<?xjs if (settings.nodelist_ibbs) { ?> <?xjs if (settings.nodelist_ibbs) { ?>
function _send_ibbs_telegram(sys, host, user) { function _send_ibbs_telegram(sys, host, user) {
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
$('#popUpModal').modal('show'); $('#popUpModal').modal('show');
} }
_sbbs_events.sbbsimsg = function (e) { registerEventListener('sbbsimsg', function (e) {
const data = JSON.parse(e.data); const data = JSON.parse(e.data);
var users = 0; var users = 0;
$('#sbbsimsg-nodelist').addClass('hidden'); $('#sbbsimsg-nodelist').addClass('hidden');
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
$('#sbbsimsg-nodelist').removeClass('hidden'); $('#sbbsimsg-nodelist').removeClass('hidden');
$('#sbbs-nodelist').parent().removeClass('hidden'); $('#sbbs-nodelist').parent().removeClass('hidden');
} }
} });
<?xjs } ?> <?xjs } ?>
</script> </script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment