From 0134c1a912b09e28121838eb59faefc188c40003 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 23 Nov 2022 18:08:21 -0500 Subject: [PATCH] webcit-ng uses biff notifications now --- webcit-ng/server/admin_functions.c | 20 ++++++++++++++++++++ webcit-ng/static/js/defs.js | 1 + webcit-ng/static/js/login.js | 8 ++++---- webcit-ng/static/js/main.js | 29 +++++++++++++++++++++++++++++ webcit-ng/static/js/view_mail.js | 14 -------------- 5 files changed, 54 insertions(+), 18 deletions(-) diff --git a/webcit-ng/server/admin_functions.c b/webcit-ng/server/admin_functions.c index 2c2d85f1f..1d193cf9b 100644 --- a/webcit-ng/server/admin_functions.c +++ b/webcit-ng/server/admin_functions.c @@ -84,6 +84,21 @@ void whoami(struct http_transaction *h, struct ctdlsession *c) { } +// /ctdl/a/biff returns the number of new messages that have arrived in the inbox +// since the beginning of the session or since the last call to biff +void biff(struct http_transaction *h, struct ctdlsession *c) { + char biffbuff[1024]; + + ctdl_printf(c, "BIFF"); // send the command + ctdl_readline(c, biffbuff, sizeof(biffbuff)); // read the result + h->response_code = 200; + h->response_string = strdup("OK"); + add_response_header(h, strdup("Content-type"), strdup("text/plain")); + h->response_body = strdup(&biffbuff[4]); + h->response_body_length = strlen(h->response_body); +} + + // Dispatcher for paths starting with /ctdl/a/ void ctdl_a(struct http_transaction *h, struct ctdlsession *c) { if (!strcasecmp(h->url, "/ctdl/a/login")) { // log in @@ -101,5 +116,10 @@ void ctdl_a(struct http_transaction *h, struct ctdlsession *c) { return; } + if (!strcasecmp(h->url, "/ctdl/a/biff")) { // check for new messages in the inbox + biff(h, c); + return; + } + do_404(h); // unknown } diff --git a/webcit-ng/static/js/defs.js b/webcit-ng/static/js/defs.js index ca896793c..33ed987fa 100644 --- a/webcit-ng/static/js/defs.js +++ b/webcit-ng/static/js/defs.js @@ -23,6 +23,7 @@ var room_mtime = 0; var can_delete_messages = 0; var messages_per_page = 20; var march_list = [] ; +var new_mail = 0; // List of defined views shamelessly swiped from libcitadel headers diff --git a/webcit-ng/static/js/login.js b/webcit-ng/static/js/login.js index 7c555e99c..b9e80a0cc 100644 --- a/webcit-ng/static/js/login.js +++ b/webcit-ng/static/js/login.js @@ -40,10 +40,10 @@ function display_login_screen(any_message) { // When the user elects to log out, we just call /ctdl/a/logout and let the system flush the session. // When we go back to ctdl_startup() it will detect that we are no longer logged in, and do the right thing. //function logout() { -logout = async() => { - response = await fetch("/ctdl/a/logout"); - ctdl_startup(); // let the regular startup code take care of everything else -} +//logout = async() => { + //response = await fetch("/ctdl/a/logout"); + //ctdl_startup(); // let the regular startup code take care of everything else +//} function login_button(username) { diff --git a/webcit-ng/static/js/main.js b/webcit-ng/static/js/main.js index 0ebb577a0..95c6557a9 100644 --- a/webcit-ng/static/js/main.js +++ b/webcit-ng/static/js/main.js @@ -4,8 +4,28 @@ // disclosure are subject to the GNU General Public License v3. +do_biff = async() => { + response = await fetch("/ctdl/a/biff"); + if (response.ok) { + biff_result = await(response.text()); + try { + new_mail += parseInt(biff_result); + } + catch { + } + } + + if (new_mail > 0) { + console.log("YOU'VE GOT MAIL!"); + new_mail_sound.play(); // FIXME do a visual notification as well + new_mail = 0; + } +} + + // This is called at the very beginning of the main page load. ctdl_startup = async() => { + var BiffInterval; response = await fetch("/ctdl/c/info"); if (response.ok) { @@ -24,6 +44,15 @@ ctdl_startup = async() => { else { // Otherwise, display_login_screen(""); // display the login modal. } + + var BiffInterval; + try { // if this was already set up, clear it so there aren't multiple + clearInterval(BiffInterval); + } + catch { + } + do_biff(); + BiffInterval = setInterval(do_biff, 10000); } else { document.getElementById("ctdl-main").innerHTML = diff --git a/webcit-ng/static/js/view_mail.js b/webcit-ng/static/js/view_mail.js index eeda88fc3..c1911a3ba 100644 --- a/webcit-ng/static/js/view_mail.js +++ b/webcit-ng/static/js/view_mail.js @@ -261,20 +261,6 @@ function render_mailbox_display(notify) { if (selected_message > 0) { // if we had a message selected, keep it selected select_message(selected_message); } - - - - -/* - if ( (do_notify > 0) && (notify == newmail_notify.YES) ) { - console.log(do_notify + " new mail"); - new_mail_sound.play(); // FIXME do a visual notification as well - // FIXME move this to BIFF - } - */ - - - } } fetch_mailbox(); -- 2.39.2