]> code.citadel.org Git - citadel.git/commitdiff
Added the logic to auto-refresh mailbox display
authorArt Cancro <ajc@citadel.org>
Mon, 4 Jul 2022 04:24:48 +0000 (00:24 -0400)
committerArt Cancro <ajc@citadel.org>
Mon, 4 Jul 2022 04:24:48 +0000 (00:24 -0400)
webcit-ng/static/js/view_forum.js
webcit-ng/static/js/view_mail.js

index febf7f13018c5159e08bf5ebaeccea13d5e4d169..2611f18cabdae831bfc24bc504e915fa2b027424 100644 (file)
@@ -1,3 +1,5 @@
+// This module handles the view for "forum" (message board) rooms.
+//
 // Copyright (c) 2016-2022 by the citadel.org team
 //
 // This program is open source software.  Use, duplication, or
index ec40e6718f38191268bb71482f74683138e8c4c5..5b1c915e6907aab440e9aa0eb4d62983e19f0483 100644 (file)
@@ -1,11 +1,31 @@
+// This module handles the view for "mailbox" rooms.
+//
 // Copyright (c) 2016-2022 by the citadel.org team
 //
 // This program is open source software.  Use, duplication, or
 // disclosure are subject to the GNU General Public License v3.
 
 
+// Remember the last message that was selected
+var selected_message = 0;
+var RefreshMailboxInterval;
+
+
 // A message has been selected...
 function select_message(msgnum) {
+       // unhighlight any previously selected message
+       try {
+               document.getElementById("ctdl-msgsum-" + selected_message).classList.remove("w3-blue");
+       }
+       catch {
+       }
+
+       // highlight the newly selected message
+       selected_message = msgnum;
+       document.getElementById("ctdl-msgsum-" + selected_message).classList.add("w3-blue");
+       document.getElementById("ctdl-msgsum-" + selected_message).scrollIntoView();
+
+       // display the message
        reading_pane = document.getElementById("ctdl-reading-pane").innerHTML = "message selected " + msgnum ;
 }
 
@@ -13,8 +33,10 @@ function select_message(msgnum) {
 // render one row in the mailbox table (this could be called from one of several places)
 function mail_render_row(msg) {
        row     = "<tr "
-               + "id=\"ctdl-msgsum-" + msg["msgnum"] + "\""
-               + "onClick=\"select_message(" + msg["msgnum"] + ")\""
+               + "id=\"ctdl-msgsum-" + msg["msgnum"] + "\" "
+               + "onClick=\"select_message(" + msg["msgnum"] + ");\" "
+               //+ "onmouseenter=\"console.log('mouse in');\" "
+               //+ "onmouseleave=\"console.log('mouse out');\""
                + ">"
                + "<td>" + msg["subject"] + "</td>"
                + "<td>" + msg["author"] + " &lt;" + msg["addr"] + "&gt;</td>"
@@ -27,19 +49,35 @@ function mail_render_row(msg) {
 
 // Set up the mailbox view
 function mail_display() {
-       target_div = document.getElementById("ctdl-main");
-       target_div.innerHTML = "<div id=\"ctdl-mailbox-pane\">mailbox pane</div><div id=\"ctdl-reading-pane\">reading pane</div>";
-       mailbox_pane = document.getElementById("ctdl-mailbox-pane");
-       reading_pane = document.getElementById("ctdl-reading-pane");
+       document.getElementById("ctdl-main").innerHTML = "<div id=\"ctdl-mailbox-pane\">mailbox pane</div><div id=\"ctdl-reading-pane\">reading pane</div>";
+       refresh_mail_display();
+       RefreshMailboxInterval = setInterval(refresh_mail_display, 10000);
+}
 
-       activate_loading_modal();
+
+// Display or refresh the mailbox
+function refresh_mail_display() {
+       console.log("refresh_mail_display()");
+
+       // If the "ctdl-mailbox-pane" no longer exists, the user has navigated to a different part of the site,
+       // so cancel the refresh.
+       try {
+               document.getElementById("ctdl-mailbox-pane").innerHTML;
+       }
+       catch {
+               console.log("ending refresh_mail_display()");
+               clearInterval(RefreshMailboxInterval);
+               return;
+       }
+
+       // Now go to the server.
        url = "/ctdl/r/" + escapeHTMLURI(current_room) + "/mailbox";
        fetch_mailbox = async() => {
                response = await fetch(url);
                msgs = await(response.json());
                if (response.ok) {
 
-                       box =   "<table class=\"w3-table-all\" width=100%>"
+                       box =   "<table class=\"w3-table-all w3-hoverable\" width=100%>"
                                + "<tr class=\"w3-blue\">"
                                + "<th>" + _("Subject") + "</th>"
                                + "<th>" + _("Sender") + "</th>"
@@ -52,9 +90,12 @@ function mail_display() {
                        }
 
                        box +=  "</table>";
-                       mailbox_pane.innerHTML = box;
+                       document.getElementById("ctdl-mailbox-pane").innerHTML = box;
+
+                       if (selected_message > 0) {                     // if we had a message selected, keep it selected
+                               select_message(selected_message);
+                       }
                }
        }
        fetch_mailbox();
-       deactivate_loading_modal();
 }