Mailbox refresh is working completely now.
authorArt Cancro <ajc@citadel.org>
Sat, 16 Jul 2022 17:08:16 +0000 (13:08 -0400)
committerArt Cancro <ajc@citadel.org>
Sat, 16 Jul 2022 17:08:16 +0000 (13:08 -0400)
webcit-ng/README.txt
webcit-ng/room_functions.c
webcit-ng/static/js/view_mail.js

index 56b320021995f83c8160968f57b0f0d07465f6d0..25e90ab29b17cf07e89e93a86636d6e041e43b63 100644 (file)
@@ -7,8 +7,8 @@ layered with as little spaghetti as possible.
 Please don't mess with this yet.  I'm only pushing it upstream so it gets backed up.
 
 
 Please don't mess with this yet.  I'm only pushing it upstream so it gets backed up.
 
 
-DESIGN GOALS:
--------------
+DESIGN GOALS
+------------
 
 *      Hold as little state as possible
 
 
 *      Hold as little state as possible
 
@@ -29,7 +29,8 @@ REST format URLs will generally take the form of:
 
        /ctdl/objectClass/[container/]object[/operation]
 
 
        /ctdl/objectClass/[container/]object[/operation]
 
-We are using:
+We are using
+------------
 
 *      libcitadel for information about the Citadel server, some string handling, and the JSON encoder
 *      Expat for DAV handling
 
 *      libcitadel for information about the Citadel server, some string handling, and the JSON encoder
 *      Expat for DAV handling
index d2e75f55b0ad8a9c8faa70a419012e71fbd7eb21..67b3e9082943ca78a952b0048e00c6d8fa9a3ff5 100644 (file)
@@ -80,7 +80,6 @@ void json_stat(struct http_transaction *h, struct ctdlsession *c) {
 
        ctdl_printf(c, "STAT");
        ctdl_readline(c, buf, sizeof(buf));
 
        ctdl_printf(c, "STAT");
        ctdl_readline(c, buf, sizeof(buf));
-       syslog(LOG_DEBUG, "%s", buf);
        if (buf[0] == '2') {
                JsonValue *j = NewJsonObject(HKEY("stat"));
                extract_token(field, &buf[4], 0, '|', sizeof field);
        if (buf[0] == '2') {
                JsonValue *j = NewJsonObject(HKEY("stat"));
                extract_token(field, &buf[4], 0, '|', sizeof field);
index b53cb7adce68280281283dc2cd3717be175a2260..c104c429827217b848db5526b1fdb08b29dca454 100644 (file)
@@ -8,7 +8,6 @@
 
 var selected_message = 0;                                                      // Remember the last message that was selected
 var RefreshMailboxInterval;                                                    // We store our refresh timer here
 
 var selected_message = 0;                                                      // Remember the last message that was selected
 var RefreshMailboxInterval;                                                    // We store our refresh timer here
-var last_mtime;                                                                        // Watch this mailbox using the room's mtime
 
 
 // Render a message into the mailbox view
 
 
 // Render a message into the mailbox view
@@ -140,8 +139,7 @@ function mail_display() {
                = "<div id=\"ctdl-reading-pane\" class=\"ctdl-reading-pane\"></div>"
        ;
 
                = "<div id=\"ctdl-reading-pane\" class=\"ctdl-reading-pane\"></div>"
        ;
 
-       last_mtime = 0;                                         // Keep track of room's mod time so we know when to refresh
-       refresh_mail_display();
+       render_mailbox_display();
        try {                                                   // if this was already set up, clear it so there aren't multiple
                clearInterval(RefreshMailboxInterval);
        }
        try {                                                   // if this was already set up, clear it so there aren't multiple
                clearInterval(RefreshMailboxInterval);
        }
@@ -151,7 +149,7 @@ function mail_display() {
 }
 
 
 }
 
 
-// Display or refresh the mailbox
+// Refresh the mailbox, either for the first time or whenever needed
 function refresh_mail_display() {
 
        // If the "ctdl-mailbox-pane" no longer exists, the user has navigated to a different part of the site,
 function refresh_mail_display() {
 
        // If the "ctdl-mailbox-pane" no longer exists, the user has navigated to a different part of the site,
@@ -166,12 +164,23 @@ function refresh_mail_display() {
                return;
        }
 
                return;
        }
 
-       if (last_mtime == 0) {
-               last_mtime = room_mtime;
+       // Ask the server if the room has been written to since our last look at it.
+       url = "/ctdl/r/" + escapeHTMLURI(current_room) + "/stat";
+       fetch_stat = async() => {
+               response = await fetch(url);
+               stat = await(response.json());
+               if (stat.room_mtime > room_mtime) {
+                       room_mtime = stat.room_mtime;
+                       render_mailbox_display();
+               }
        }
        }
-       console.log("refresh_mail_display() last_mtime is " + last_mtime + " FIXME");
+       fetch_stat();
+}
+
+
+// This is where the rendering of the message list in the mailbox view is performed.
+function render_mailbox_display() {
 
 
-       // Now go to the server.
        url = "/ctdl/r/" + escapeHTMLURI(current_room) + "/mailbox";
        fetch_mailbox = async() => {
                response = await fetch(url);
        url = "/ctdl/r/" + escapeHTMLURI(current_room) + "/mailbox";
        fetch_mailbox = async() => {
                response = await fetch(url);