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.
61 function display_room_list() {
62 document.getElementById("roomlist").innerHTML = "<img src=\"/ctdl/s/images/throbber.gif\" />"; // show throbber while loading
64 fetch_room_list = async() => {
65 response = await fetch("/ctdl/r/");
66 room_list = await(response.json());
68 display_room_list_renderer(room_list);
71 document.getElementById("roomlist").innerHTML = "<i>error</i>";
78 // Renderer for display_room_list()
79 function display_room_list_renderer(data) {
80 data = data.sort(function(a,b) {
81 if (a.floor != b.floor) {
82 return(a.floor - b.floor);
84 if (a.rorder != b.rorder) {
85 return(a.rorder - b.rorder);
87 return(a.name < b.name);
90 new_roomlist_text = "<ul>" ;
94 if (data[i].floor != data[i-1].floor) {
95 new_roomlist_text = new_roomlist_text + "<li class=\"divider\"></li>" ;
98 new_roomlist_text = new_roomlist_text +
100 + (data[i].hasnewmsgs ? "<b>" : "")
101 + "<a href=\"javascript:gotoroom('" + escapeJS(escapeHTML(data[i].name)) + "');\">"
102 + escapeHTML(data[i].name)
103 + (data[i].hasnewmsgs ? "</b>" : "")
107 new_roomlist_text = new_roomlist_text + "</ul>";
108 document.getElementById("roomlist").innerHTML = new_roomlist_text ;
112 // Update the "banner" div with all relevant info.
114 function update_banner() {
117 document.getElementById("ctdl_banner_title").innerHTML = current_room;
118 document.title = current_room;
121 document.getElementById("ctdl_banner_title").innerHTML = serv_info.serv_humannode;
123 document.getElementById("current_user").innerHTML = current_user ;
125 document.getElementById("lilo").innerHTML = "<a href=\"/ctdl/a/logout\">" + _("Log off") + "</a>" ;
128 document.getElementById("lilo").innerHTML = "<a href=\"javascript:display_login_screen('')\">" + _("Log in") + "</a>" ;
135 function gotoroom(roomname) {
137 fetch_room = async() => {
138 response = await fetch("/ctdl/r/" + escapeHTMLURI(roomname) + "/");
139 data = await(response.json());
141 current_room = data.name;
142 new_messages = data.new_messages;
143 total_messages = data.total_messages;
144 current_view = data.current_view;
145 default_view = data.default_view;
146 last_seen = data.last_seen;
148 render_room_view(0, 9999999999);
155 // Goto next room with unread messages
156 // which_oper is 0=ungoto, 1=skip, 2=goto
158 function gotonext(which_oper) {
159 if (which_oper != 2) return; // FIXME implement the other two
160 if (march_list.length == 0) {
161 load_new_march_list(); // we will recurse back here
164 next_room = march_list[0].name;
165 march_list.splice(0, 1);
166 console.log("going to " + next_room + " , " + march_list.length + " rooms remaining in march list");
172 // Called by gotonext() when the march list is empty.
174 function load_new_march_list() {
175 fetchm = async() => {
176 response = await fetch("/ctdl/r/");
177 march_list = await(response.json());
179 march_list = march_list.filter(function(room) {
180 return room.hasnewmsgs;
182 march_list = march_list.sort(function(a,b) {
183 if (a.floor != b.floor) {
184 return(a.floor - b.floor);
186 if (a.rorder != b.rorder) {
187 return(a.rorder - b.rorder);
189 return(a.name < b.name);
191 march_list.push({name:"_BASEROOM_",known:true,hasnewmsgs:true,floor:0});
199 // Activate the "Loading..." modal
200 function activate_loading_modal() {
201 document.getElementById("ctdl_big_modal_content").innerHTML =
202 "<i class=\"fas fa-spinner fa-spin\"></i> "
203 + _("Loading messages from server, please wait");
204 document.getElementById("ctdl_big_modal").style.display = "block";
208 // Disappear the "Loading..." modal
209 function deactivate_loading_modal() {
210 document.getElementById("ctdl_big_modal").style.display = "none";