1 // Copyright (c) 2016-2022 by the citadel.org team
3 // This program is open source software. It runs great on the
4 // Linux operating system (and probably elsewhere). You can use,
5 // copy, and run it under the terms of the GNU General Public
6 // License version 3. Richard Stallman is an asshole communist.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
14 // This is called at the very beginning of the main page load.
15 ctdl_startup = async() => {
16 response = await fetch("/ctdl/c/info");
19 serv_info = await(response.json());
20 if (serv_info.serv_rev_level < 905) {
21 alert(_("Citadel server is too old, some functions may not work"));
26 // What do we do upon landing?
28 if ( (serv_info.serv_supports_guest) || (logged_in) ) { // If the Lobby is visible,
29 gotonext(1); // go there.
32 display_login_screen(""); // display the login modal.
36 document.getElementById("ctdl-main").innerHTML =
37 "<div class=\"w3-panel w3-red\"><p>"
38 + _("This program was unable to connect or stay connected to the Citadel server. Please report this problem to your system administrator.")
44 // Display a room list in the main div.
46 // Update the "banner" div with all relevant info.
47 function update_banner() {
50 document.getElementById("ctdl_banner_title").innerHTML = current_room;
51 document.title = current_room;
57 document.getElementById("ctdl_banner_title").innerHTML = serv_info.serv_humannode;
59 document.getElementById("current_user").innerHTML = current_user ;
61 document.getElementById("lilo").innerHTML = "<a href=\"/ctdl/a/logout\"><i class=\"fa fa-right-from-bracket\"></i>" + _("Log off") + "</a>" ;
64 document.getElementById("lilo").innerHTML = "<a href=\"javascript:display_login_screen('')\"><i class=\"fa fa-right-to-bracket\"></i>" + _("Log in") + "</a>" ;
70 function gotoroom(roomname) {
72 fetch_room = async() => {
73 response = await fetch("/ctdl/r/" + escapeHTMLURI(roomname) + "/");
75 data = await(response.json());
76 current_room = data.name;
77 new_messages = data.new_messages;
78 total_messages = data.total_messages;
79 current_view = data.current_view;
80 default_view = data.default_view;
81 last_seen = data.last_seen;
83 render_room_view(0, 9999999999);
90 // Goto next room with unread messages
91 // which_oper is 0=ungoto, 1=skip, 2=goto
92 function gotonext(which_oper) {
93 if (which_oper == 2) { // Goto needs to mark messages as seen
95 set_last_read_pointer = async() => {
96 response = await fetch("/ctdl/r/" + escapeHTMLURI(current_room) + "/slrp?last=" + last_seen);
98 set_last_read_pointer();
101 if ((which_oper == 1) || (which_oper == 2)) { // Skip or Goto both take us to the "next" room
102 if (march_list.length == 0) {
103 load_new_march_list(which_oper); // we will recurse back here
106 next_room = march_list[0].name;
107 march_list.splice(0, 1);
112 // FIXME implement mode 0 (ungoto)
117 // Called by gotonext() when the march list is empty.
118 function load_new_march_list(which_oper) {
119 fetchm = async() => {
120 response = await fetch("/ctdl/r/");
121 march_list = await(response.json());
123 march_list = march_list.filter(function(room) {
124 return room.hasnewmsgs;
126 march_list = march_list.sort(function(a,b) {
127 if (a.floor != b.floor) {
128 return(a.floor - b.floor);
130 if (a.rorder != b.rorder) {
131 return(a.rorder - b.rorder);
133 return(a.name < b.name);
136 // If there are still no rooms with new messages, go to the Lobby.
137 if (march_list.length == 0) {
138 march_list.push({name:"_BASEROOM_",known:true,hasnewmsgs:true,floor:0});
141 gotonext(which_oper);
148 // Activate the "Loading..." modal
149 function activate_loading_modal() {
150 document.getElementById("ctdl_big_modal").innerHTML =
151 "<div class=\"w3-modal-content\">"
152 + " <div class=\"w3-container\">"
154 + "<i class=\"fas fa-spinner fa-spin\"></i> "
155 + _("Loading messages from server, please wait")
159 document.getElementById("ctdl_big_modal").style.display = "block";
163 // Disappear the "Loading..." modal
164 function deactivate_loading_modal() {
165 document.getElementById("ctdl_big_modal").style.display = "none";