track c_lastseen so we can use it in read operations
[citadel.git] / webcit-ng / static / js / views.js
index 33da436676fe35ba3e7efcacc5c9058a3aa2c64b..ba1be92108cb2f04413fffdd5da1c0bd751f164c 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Copyright (c) 2016-2017 by the citadel.org team
+// Copyright (c) 2016-2018 by the citadel.org team
 //
 // This program is open source software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License version 3.
@@ -32,12 +32,13 @@ var views = {
 // This function is the dispatcher that determines the correct view for a room,
 // and calls the correct renderer.
 //
-function render_room_view() {
-
-       switch(current_view) {
+function render_room_view()
+{
+       switch(current_view)
+       {
                case views.VIEW_MAILBOX:                                                // FIXME view mail rooms as forums for now
                case views.VIEW_BBS:
-                       threads_readmessages();
+                       forum_readmessages("flat");
                        break;
                default:
                        document.getElementById("main").innerHTML = "The view for " + current_room + " is " + current_view + " but there is no renderer." ;
@@ -47,21 +48,29 @@ function render_room_view() {
 }
 
 
-// bbs "threads" view
+// Forum view -- flat or threaded
 // The inner div exists so that if the user clicks away early, the main div doesn't get clobbered when the load completes.
+// The parameter can be set to "flat" or "threads" which is passed directly to the API
 //
-function threads_readmessages() {
+function XX_forum_readmessages(flat_or_threads)
+{
        var innerdivname = randomString(5);
-       document.getElementById("main").innerHTML = "<div id=\"" + innerdivname + "\"><img src=\"/ctdl/s/throbber.gif\" />" + _("Loading messages from server, please wait") + "</div>" ;
+       document.getElementById("main").innerHTML = "<div id=\"" + innerdivname +
+               "\"><br><br><br><center><h5><i class=\"fas fa-spinner fa-spin\"></i>&nbsp;&nbsp;"
+               + _("Loading messages from server, please wait") + "</h5></center></div>" ;
 
        var request = new XMLHttpRequest();
-       request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/" + "threads", true);
-       request.onreadystatechange = function() {
-               if (this.readyState === 4) {
-                       if ((this.status / 100) == 2) {
+       request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/" + flat_or_threads, true);
+       request.onreadystatechange = function()
+       {
+               if (this.readyState === 4)
+               {
+                       if ((this.status / 100) == 2)
+                       {
                                document.getElementById(innerdivname).outerHTML = this.responseText;
                        }
-                       else {
+                       else
+                       {
                                document.getElementById(innerdivname).outerHTML = "ERROR " + this.status ;
                        }
                }
@@ -69,3 +78,39 @@ function threads_readmessages() {
        request.send();
        request = null;
 }
+
+
+// Forum view -- let's have another go at this with the rendering done client-side
+//
+function forum_readmessages(flat_or_threads)
+{
+       var innerdivname = randomString(5);
+       document.getElementById("main").innerHTML = "<div id=\"" + innerdivname +
+               "\"><br><br><br><center><h5><i class=\"fas fa-spinner fa-spin\"></i>&nbsp;&nbsp;"
+               + _("Loading messages from server, please wait") + "</h5></center></div>" ;
+
+       var request = new XMLHttpRequest();
+       request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/msgs.all", true);
+       request.onreadystatechange = function()
+       {
+               if (this.readyState === 4)
+               {
+                       if ((this.status / 100) == 2)
+                       {
+                               document.getElementById(innerdivname).innerHTML = "Are we logged in? " + logged_in + "<br>" + "Last seen: " + last_seen + "<br><ul>" ;
+                               msgs = JSON.parse(this.responseText);
+                               for (var i in msgs)
+                               {
+                                       document.getElementById(innerdivname).innerHTML += "<li>" + msgs[i] + "</li>" ;
+                               }
+                               document.getElementById(innerdivname).innerHTML += "</ul>" ;
+                       }
+                       else
+                       {
+                               document.getElementById(innerdivname).innerHTML = this.status ;         // error message
+                       }
+               }
+       };
+       request.send();
+       request = null;
+}