}
+// Client is requesting a STAT (name and modification time) of the current room
+void json_stat(struct http_transaction *h, struct ctdlsession *c) {
+ char buf[1024];
+ char field[1024];
+
+ 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);
+ JsonObjectAppend(j, NewJsonPlainString(HKEY("name"), field, -1));
+ JsonObjectAppend(j, NewJsonNumber(HKEY("room_mtime"), extract_long(&buf[4], 1)));
+
+ StrBuf *sj = NewStrBuf();
+ SerializeJson(sj, j, 1); // '1' == free the source array
+ add_response_header(h, strdup("Content-type"), strdup("application/json"));
+ h->response_code = 200;
+ h->response_string = strdup("OK");
+ h->response_body_length = StrLength(sj);
+ h->response_body = SmashStrBuf(&sj);
+ }
+ else {
+ do_404(h);
+ }
+ return;
+}
+
+
// Client is requesting a mailbox summary of the current room
void json_mailbox(struct http_transaction *h, struct ctdlsession *c) {
char buf[1024];
return;
}
+ if (!strcasecmp(buf, "stat")) { // Client is requesting a stat command (name and modification time)
+ json_stat(h, c);
+ return;
+ }
+
if (!strncasecmp(buf, "msgs.", 5)) { // Client is requesting a list of message numbers
unescape_input(&buf[5]);
json_msglist(h, c, &buf[5]);
JsonObjectAppend(j, NewJsonNumber(HKEY("new_messages"), c->new_messages));
JsonObjectAppend(j, NewJsonNumber(HKEY("total_messages"), c->total_messages));
JsonObjectAppend(j, NewJsonNumber(HKEY("last_seen"), c->last_seen));
+ JsonObjectAppend(j, NewJsonNumber(HKEY("room_mtime"), c->room_mtime));
+ JsonObjectAppend(j, NewJsonNumber(HKEY("new_mail"), c->new_mail));
StrBuf *sj = NewStrBuf();
SerializeJson(sj, j, 1); // '1' == free the source array
c->last_seen = extract_long(&buf[4], 6); // The highest message number the user has read in this room
// 7 (int)rmailflag Boolean flag: 1 if this is a Mail> room, 0 otherwise.
c->is_room_aide = extract_int(&buf[4], 8);
- // 9 (int)newmailcount The number of new Mail messages the user has
+ c->new_mail = extract_int(&buf[4], 9); // the number of new messages in the user's INBOX
// 10 (int)CC->room.QRfloor The floor number this room resides on
c->room_current_view = extract_int(&buf[4], 11);
c->room_default_view = extract_int(&buf[4], 12);
// 13 (int)is_trash Boolean flag: 1 if this is the user's Trash folder, 0 otherwise.
room_flags2 = extract_long(&buf[4], 14); // More flags associated with this room.
- // 15 (long)CC->room.QRmtime Timestamp of the last write activity in this room
+ c->room_mtime = extract_long(&buf[4], 15); // Timestamp of the last write activity in this room
// If any of these three conditions are met, let the client know it has permission to delete messages.
if ((c->is_room_aide) || (room_flags & QR_MAILBOX) || (room_flags2 & QR2_COLLABDEL)) {
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
= "<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();
try { // if this was already set up, clear it so there aren't multiple
clearInterval(RefreshMailboxInterval);
// 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 {
return;
}
+ if (last_mtime == 0) {
+ last_mtime = room_mtime;
+ }
+ console.log("refresh_mail_display() last_mtime is " + last_mtime + " FIXME");
+
// Now go to the server.
url = "/ctdl/r/" + escapeHTMLURI(current_room) + "/mailbox";
fetch_mailbox = async() => {