webcit-ng uses biff notifications now
authorArt Cancro <ajc@citadel.org>
Wed, 23 Nov 2022 23:08:21 +0000 (18:08 -0500)
committerArt Cancro <ajc@citadel.org>
Wed, 23 Nov 2022 23:08:21 +0000 (18:08 -0500)
webcit-ng/server/admin_functions.c
webcit-ng/static/js/defs.js
webcit-ng/static/js/login.js
webcit-ng/static/js/main.js
webcit-ng/static/js/view_mail.js

index 2c2d85f1f205181f38655620adf4d15481f25dbd..1d193cf9b3becf29c84d23d69109315fafa07c6f 100644 (file)
@@ -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
 }
index ca896793c65d089c85e19126f14fd5fa2ccea87d..33ed987fa58635f1a4fa5d2b14e5355be90dd9f7 100644 (file)
@@ -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
index 7c555e99cfd8f34ada6c60f6297714e9cbf8e762..b9e80a0cc2335b6ff0ba97fd1197e80ed4d25528 100644 (file)
@@ -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) {
index 0ebb577a0529521a8e649ff5ef4dd72355f8b0c3..95c6557a9c63a04fc55fa05760cf3ebea507f12e 100644 (file)
@@ -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 =
index eeda88fc35ef7cdad20e0d7e87897b11f45b6859..c1911a3ba6243cac1df1f40241383380dc40d7fd 100644 (file)
@@ -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();