2 // Copyright (c) 2016-2020 by the citadel.org team
4 // This program is open source software. It runs great on the
5 // Linux operating system (and probably elsewhere). You can use,
6 // copy, and run it under the terms of the GNU General Public
7 // License version 3. Richard Stallman is an asshole communist.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
15 var current_room = "_BASEROOM_";
17 var total_messages = 0;
21 var current_user = _("Not logged in.");
24 var messages_per_page = 20;
28 // Placeholder for when we add i18n later
34 // This is called at the very beginning of the main page load.
36 ctdl_startup = async() => {
37 response = await fetch("/ctdl/c/info");
40 serv_info = await(response.json());
41 if (serv_info.serv_rev_level < 905) {
42 alert(_("Citadel server is too old, some functions may not work"));
47 // for now, show a room list in the main div
48 gotoroom("_BASEROOM_");
52 document.getElementById("ctdl-main").innerHTML =
53 "<div class=\"w3-panel w3-red\"><p>"
54 + _("This program was unable to connect or stay connected to the Citadel server. Please report this problem to your system administrator.")
60 // Display a room list in the main div.
62 function display_room_list() {
63 document.getElementById("roomlist").innerHTML = "<img src=\"/ctdl/s/static/throbber.gif\" />"; // show throbber while loading
65 fetch_room_list = async() => {
66 response = await fetch("/ctdl/r/");
67 room_list = await(response.json());
69 display_room_list_renderer(room_list);
76 // Renderer for display_room_list()
78 function display_room_list_renderer(data) {
79 data = data.sort(function(a,b) {
80 if (a.floor != b.floor) {
81 return(a.floor - b.floor);
83 if (a.rorder != b.rorder) {
84 return(a.rorder - b.rorder);
86 return(a.name < b.name);
89 new_roomlist_text = "<ul>" ;
93 if (data[i].floor != data[i-1].floor) {
94 new_roomlist_text = new_roomlist_text + "<li class=\"divider\"></li>" ;
97 new_roomlist_text = new_roomlist_text +
99 + (data[i].hasnewmsgs ? "<b>" : "")
100 + "<a href=\"javascript:gotoroom('" + escapeJS(escapeHTML(data[i].name)) + "');\">"
101 + escapeHTML(data[i].name)
102 + (data[i].hasnewmsgs ? "</b>" : "")
106 new_roomlist_text = new_roomlist_text + "</ul>";
107 document.getElementById("roomlist").innerHTML = new_roomlist_text ;
111 // Update the "banner" div with all relevant info.
113 function update_banner() {
116 document.getElementById("ctdl_banner_title").innerHTML = current_room;
117 document.title = current_room;
120 document.getElementById("ctdl_banner_title").innerHTML = serv_info.serv_humannode;
122 document.getElementById("current_user").innerHTML = current_user ;
124 document.getElementById("lilo").innerHTML = "<a href=\"/ctdl/a/logout\">" + _("Log off") + "</a>" ;
127 document.getElementById("lilo").innerHTML = "<a href=\"javascript:display_login_screen('')\">" + _("Log in") + "</a>" ;
134 function gotoroom(roomname) {
136 fetch_room = async() => {
137 response = await fetch("/ctdl/r/" + escapeHTMLURI(roomname) + "/");
138 data = await(response.json());
140 current_room = data.name;
141 new_messages = data.new_messages;
142 total_messages = data.total_messages;
143 current_view = data.current_view;
144 default_view = data.default_view;
145 last_seen = data.last_seen;
147 render_room_view(0, 9999999999);
154 // Goto next room with unread messages
155 // which_oper is 0=ungoto, 1=skip, 2=goto
157 function gotonext(which_oper) {
158 if (which_oper != 2) return; // FIXME implement the other two
159 if (march_list.length == 0) {
160 load_new_march_list(); // we will recurse back here
163 next_room = march_list[0].name;
164 march_list.splice(0, 1);
165 console.log("going to " + next_room + " , " + march_list.length + " rooms remaining in march list");
171 // Called by gotonext() when the march list is empty.
173 function load_new_march_list() {
174 fetchm = async() => {
175 response = await fetch("/ctdl/r/");
176 march_list = await(response.json());
178 march_list = march_list.filter(function(room) {
179 return room.hasnewmsgs;
181 march_list = march_list.sort(function(a,b) {
182 if (a.floor != b.floor) {
183 return(a.floor - b.floor);
185 if (a.rorder != b.rorder) {
186 return(a.rorder - b.rorder);
188 return(a.name < b.name);
190 march_list.push({name:"_BASEROOM_",known:true,hasnewmsgs:true,floor:0});
198 // Activate the "Loading..." modal
199 function activate_loading_modal() {
200 document.getElementById("ctdl_big_modal_content").innerHTML =
201 "<i class=\"fas fa-spinner fa-spin\"></i> "
202 + _("Loading messages from server, please wait");
203 document.getElementById("ctdl_big_modal").style.display = "block";
207 // Disappear the "Loading..." modal
208 function deactivate_loading_modal() {
209 document.getElementById("ctdl_big_modal").style.display = "none";