]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/static/js/main.js
Grammar change in the license declaration.
[citadel.git] / webcit-ng / static / js / main.js
index 039a1e64b04a9ef2568b2b81642796b4eeaa382b..6af9c1421fc69c99b6ef7c973d75071f4bb1a6ef 100644 (file)
@@ -1,32 +1,25 @@
-// Copyright (c) 2016-2022 by the citadel.org team
+// Copyright (c) 2016-2023 by the citadel.org team
 //
-// This program is open source software.  It runs great on the
-// Linux operating system (and probably elsewhere).  You can use,
-// copy, and run it under the terms of the GNU General Public
-// License version 3.  Richard Stallman is an asshole communist.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-
-var current_room = "_BASEROOM_";
-var new_messages = 0;
-var total_messages = 0;
-var default_view = 0;
-var current_view = 0;
-var logged_in = 0;
-var current_user = _("Not logged in.");
-var serv_info;
-var last_seen = 0;
-var messages_per_page = 20;
-var march_list = [] ;
-
-
-// Placeholder for when we add i18n later
-function _(x) {
-       return x;
+// This program is open source software.  Use, duplication, or
+// disclosure is 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 = " + new_mail);
+               new_mail_sound.play();                  // FIXME do a visual notification as well
+               new_mail = 0;
+       }
 }
 
 
@@ -50,10 +43,19 @@ ctdl_startup = async() => {
                else {                                                                  // Otherwise,
                        display_login_screen("");                                       // display the login modal.
                }
+
+               var biff_interval;
+               try {                                                                   // if this was already set up,
+                       clearInterval(biff_interval);                                   // clear the old one so there's only one.
+               }
+               catch {
+               }
+               do_biff();
+               biff_interval = setInterval(do_biff, 10000);
        }
        else {
                document.getElementById("ctdl-main").innerHTML =
-                       "<div class=\"w3-panel w3-red\"><p>"
+                       "<div class=\"ctdl-fatal-error\"><p>"
                        + _("This program was unable to connect or stay connected to the Citadel server.  Please report this problem to your system administrator.")
                        + "</div>";
        }
@@ -67,17 +69,26 @@ function update_banner() {
        detect_logged_in();
        if (current_room) {
                document.getElementById("ctdl_banner_title").innerHTML = current_room;
+               if (is_trash_folder) {
+                       document.getElementById("ctdl_banner_title").innerHTML += "&nbsp;<i class=\"fa fa-trash\"></i>";
+               }
+               if (is_room_aide) {
+                       document.getElementById("ctdl_banner_title").innerHTML += "&nbsp;<i class=\"fa fa-user-cog\"></i>";
+               }
                document.title = current_room;
        }
        else {
                document.getElementById("ctdl_banner_title").innerHTML = serv_info.serv_humannode;
        }
+
+       document.getElementById("current_user_avatar").innerHTML = render_userpic(current_user);
        document.getElementById("current_user").innerHTML = current_user ;
+
        if (logged_in) {
-               document.getElementById("lilo").innerHTML = "<a href=\"/ctdl/a/logout\"><i class=\"fa-regular fa-right-from-bracket\"></i>" + _("Log off") + "</a>" ;
+               document.getElementById("lilo").innerHTML = "<a href=\"/ctdl/a/logout\"><i class=\"fa fa-right-from-bracket\"></i>&nbsp;" + _("Log off") + "</a>" ;
        }
        else {
-               document.getElementById("lilo").innerHTML = "<a href=\"javascript:display_login_screen('')\">" + _("Log in") + "</a>" ;
+               document.getElementById("lilo").innerHTML = "<a href=\"javascript:display_login_screen('')\"><i class=\"fa fa-right-to-bracket\"></i>&nbsp;" + _("Log in") + "</a>" ;
        }
 }
 
@@ -95,8 +106,12 @@ function gotoroom(roomname) {
                        current_view = data.current_view;
                        default_view = data.default_view;
                        last_seen = data.last_seen;
+                       is_room_aide = data.is_room_aide;
+                       is_trash_folder = data.is_trash_folder;
+                       room_mtime = data.room_mtime;
+                       can_delete_messages = data.can_delete_messages;
                        update_banner();
-                       render_room_view(0, 9999999999);
+                       render_room_view();
                }
        }
        fetch_room();
@@ -106,20 +121,21 @@ function gotoroom(roomname) {
 // Goto next room with unread messages
 // which_oper is 0=ungoto, 1=skip, 2=goto
 function gotonext(which_oper) {
-
        if (which_oper == 2) {                                  // Goto needs to mark messages as seen
-               console.log("FIXME set lrp to " + last_seen);
+
+               set_last_read_pointer = async() => {
+                       response = await fetch("/ctdl/r/" + escapeHTMLURI(current_room) + "/slrp?last=" + last_seen);
+               }
+               set_last_read_pointer();
        }
 
        if ((which_oper == 1) || (which_oper == 2)) {           // Skip or Goto both take us to the "next" room
                if (march_list.length == 0) {
-                       console.log("Loading march list");
                        load_new_march_list(which_oper);        // we will recurse back here
                }
                else {
                        next_room = march_list[0].name;
                        march_list.splice(0, 1);
-                       console.log("going to " + next_room + " , " + march_list.length + " rooms remaining");
                        gotoroom(next_room);
                }
        }
@@ -136,7 +152,7 @@ function load_new_march_list(which_oper) {
                march_list = await(response.json());
                if (response.ok) {
                        march_list = march_list.filter(function(room) {
-                               return room.hasnewmsgs;
+                               return(room.hasnewmsgs && room.default_view == views.VIEW_BBS);
                        });
                        march_list = march_list.sort(function(a,b) {
                                if (a.floor != b.floor) {
@@ -153,7 +169,6 @@ function load_new_march_list(which_oper) {
                                march_list.push({name:"_BASEROOM_",known:true,hasnewmsgs:true,floor:0});
                        }
 
-                       console.log(march_list);
                        gotonext(which_oper);
                }
        }
@@ -164,14 +179,8 @@ function load_new_march_list(which_oper) {
 // Activate the "Loading..." modal
 function activate_loading_modal() {
        document.getElementById("ctdl_big_modal").innerHTML =
-                 "<div class=\"w3-modal-content\">"
-               + "  <div class=\"w3-container\">"
-
-               + "<i class=\"fas fa-spinner fa-spin\"></i>&nbsp;&nbsp;"
-               + _("Loading messages from server, please wait")
-
-               + "  </div>"
-               + "</div>";
+               "<i class=\"fas fa-spinner fa-spin\"></i>&nbsp;&nbsp;"
+               + _("Loading messages from server, please wait");
        document.getElementById("ctdl_big_modal").style.display = "block";
 }