1 // Copyright (c) 2016-2022 by the citadel.org team
3 // This program is open source software. Use, duplication, or
4 // disclosure are subject to the GNU General Public License v3.
8 response = await fetch("/ctdl/a/biff");
10 biff_result = await(response.text());
12 new_mail += parseInt(biff_result);
19 console.log("YOU'VE GOT MAIL!");
20 new_mail_sound.play(); // FIXME do a visual notification as well
26 // This is called at the very beginning of the main page load.
27 ctdl_startup = async() => {
29 response = await fetch("/ctdl/c/info");
32 serv_info = await(response.json());
33 if (serv_info.serv_rev_level < 905) {
34 alert(_("Citadel server is too old, some functions may not work"));
39 // What do we do upon landing?
41 if ( (serv_info.serv_supports_guest) || (logged_in) ) { // If the Lobby is visible,
42 gotonext(1); // go there.
45 display_login_screen(""); // display the login modal.
49 try { // if this was already set up, clear it so there aren't multiple
50 clearInterval(BiffInterval);
55 BiffInterval = setInterval(do_biff, 10000);
58 document.getElementById("ctdl-main").innerHTML =
59 "<div class=\"w3-panel w3-red\"><p>"
60 + _("This program was unable to connect or stay connected to the Citadel server. Please report this problem to your system administrator.")
66 // Display a room list in the main div.
68 // Update the "banner" div with all relevant info.
69 function update_banner() {
72 document.getElementById("ctdl_banner_title").innerHTML = current_room;
74 document.getElementById("ctdl_banner_title").innerHTML += " <i class=\"fa fa-user-cog\"></i>";
76 document.title = current_room;
79 document.getElementById("ctdl_banner_title").innerHTML = serv_info.serv_humannode;
81 document.getElementById("current_user").innerHTML = current_user ;
83 document.getElementById("lilo").innerHTML = "<a href=\"/ctdl/a/logout\"><i class=\"fa fa-right-from-bracket\"></i>" + _("Log off") + "</a>" ;
84 document.getElementById("current_user_avatar").innerHTML = render_userpic(current_user);
87 document.getElementById("lilo").innerHTML = "<a href=\"javascript:display_login_screen('')\"><i class=\"fa fa-right-to-bracket\"></i>" + _("Log in") + "</a>" ;
88 document.getElementById("current_user_avatar").innerHTML = "<i class=\"fa fa-user-circle fa-3x\"></i>";
94 function gotoroom(roomname) {
96 fetch_room = async() => {
97 response = await fetch("/ctdl/r/" + escapeHTMLURI(roomname) + "/");
99 data = await(response.json());
100 current_room = data.name;
101 new_messages = data.new_messages;
102 total_messages = data.total_messages;
103 current_view = data.current_view;
104 default_view = data.default_view;
105 last_seen = data.last_seen;
106 is_room_aide = data.is_room_aide;
107 room_mtime = data.room_mtime;
108 can_delete_messages = data.can_delete_messages;
117 // Goto next room with unread messages
118 // which_oper is 0=ungoto, 1=skip, 2=goto
119 function gotonext(which_oper) {
120 if (which_oper == 2) { // Goto needs to mark messages as seen
122 set_last_read_pointer = async() => {
123 response = await fetch("/ctdl/r/" + escapeHTMLURI(current_room) + "/slrp?last=" + last_seen);
125 set_last_read_pointer();
128 if ((which_oper == 1) || (which_oper == 2)) { // Skip or Goto both take us to the "next" room
129 if (march_list.length == 0) {
130 load_new_march_list(which_oper); // we will recurse back here
133 next_room = march_list[0].name;
134 march_list.splice(0, 1);
139 // FIXME implement mode 0 (ungoto)
144 // Called by gotonext() when the march list is empty.
145 function load_new_march_list(which_oper) {
146 fetchm = async() => {
147 response = await fetch("/ctdl/r/");
148 march_list = await(response.json());
150 march_list = march_list.filter(function(room) {
151 return room.hasnewmsgs;
153 march_list = march_list.sort(function(a,b) {
154 if (a.floor != b.floor) {
155 return(a.floor - b.floor);
157 if (a.rorder != b.rorder) {
158 return(a.rorder - b.rorder);
160 return(a.name < b.name);
163 // If there are still no rooms with new messages, go to the Lobby.
164 if (march_list.length == 0) {
165 march_list.push({name:"_BASEROOM_",known:true,hasnewmsgs:true,floor:0});
168 gotonext(which_oper);
175 // Activate the "Loading..." modal
176 function activate_loading_modal() {
177 document.getElementById("ctdl_big_modal").innerHTML =
178 "<div class=\"w3-modal-content\">"
179 + " <div class=\"w3-container\">"
181 + "<i class=\"fas fa-spinner fa-spin\"></i> "
182 + _("Loading messages from server, please wait")
186 document.getElementById("ctdl_big_modal").style.display = "block";
190 // Disappear the "Loading..." modal
191 function deactivate_loading_modal() {
192 document.getElementById("ctdl_big_modal").style.display = "none";