1 // Copyright (c) 2016-2023 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! new_mail = " + new_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() => {
28 response = await fetch("/ctdl/c/info");
31 serv_info = await(response.json());
32 if (serv_info.serv_rev_level < 905) {
33 alert(_("Citadel server is too old, some functions may not work"));
38 // What do we do upon landing?
40 if ( (serv_info.serv_supports_guest) || (logged_in) ) { // If the Lobby is visible,
41 gotonext(1); // go there.
44 display_login_screen(""); // display the login modal.
48 try { // if this was already set up,
49 clearInterval(biff_interval); // clear the old one so there's only one.
54 biff_interval = setInterval(do_biff, 10000);
57 document.getElementById("ctdl-main").innerHTML =
58 "<div class=\"ctdl-fatal-error\"><p>"
59 + _("This program was unable to connect or stay connected to the Citadel server. Please report this problem to your system administrator.")
65 // Display a room list in the main div.
67 // Update the "banner" div with all relevant info.
68 function update_banner() {
71 document.getElementById("ctdl_banner_title").innerHTML = current_room;
72 if (is_trash_folder) {
73 document.getElementById("ctdl_banner_title").innerHTML += " <i class=\"fa fa-trash\"></i>";
76 document.getElementById("ctdl_banner_title").innerHTML += " <i class=\"fa fa-user-cog\"></i>";
78 document.title = current_room;
81 document.getElementById("ctdl_banner_title").innerHTML = serv_info.serv_humannode;
84 document.getElementById("current_user_avatar").innerHTML = render_userpic(current_user);
85 document.getElementById("current_user").innerHTML = current_user ;
88 document.getElementById("lilo").innerHTML = "<a href=\"/ctdl/a/logout\"><i class=\"fa fa-right-from-bracket\"></i> " + _("Log off") + "</a>" ;
91 document.getElementById("lilo").innerHTML = "<a href=\"javascript:display_login_screen('')\"><i class=\"fa fa-right-to-bracket\"></i> " + _("Log in") + "</a>" ;
97 function gotoroom(roomname) {
99 fetch_room = async() => {
100 response = await fetch("/ctdl/r/" + escapeHTMLURI(roomname) + "/");
102 data = await(response.json());
103 current_room = data.name;
104 new_messages = data.new_messages;
105 total_messages = data.total_messages;
106 current_view = data.current_view;
107 default_view = data.default_view;
108 last_seen = data.last_seen;
109 is_room_aide = data.is_room_aide;
110 is_trash_folder = data.is_trash_folder;
111 room_mtime = data.room_mtime;
112 can_delete_messages = data.can_delete_messages;
121 // Goto next room with unread messages
122 // which_oper is 0=ungoto, 1=skip, 2=goto
123 function gotonext(which_oper) {
124 if (which_oper == 2) { // Goto needs to mark messages as seen
126 set_last_read_pointer = async() => {
127 response = await fetch("/ctdl/r/" + escapeHTMLURI(current_room) + "/slrp?last=" + last_seen);
129 set_last_read_pointer();
132 if ((which_oper == 1) || (which_oper == 2)) { // Skip or Goto both take us to the "next" room
133 if (march_list.length == 0) {
134 load_new_march_list(which_oper); // we will recurse back here
137 next_room = march_list[0].name;
138 march_list.splice(0, 1);
143 // FIXME implement mode 0 (ungoto)
148 // Called by gotonext() when the march list is empty.
149 function load_new_march_list(which_oper) {
150 fetchm = async() => {
151 response = await fetch("/ctdl/r/");
152 march_list = await(response.json());
154 march_list = march_list.filter(function(room) {
155 return(room.hasnewmsgs && room.default_view == views.VIEW_BBS);
157 march_list = march_list.sort(function(a,b) {
158 if (a.floor != b.floor) {
159 return(a.floor - b.floor);
161 if (a.rorder != b.rorder) {
162 return(a.rorder - b.rorder);
164 return(a.name < b.name);
167 // If there are still no rooms with new messages, go to the Lobby.
168 if (march_list.length == 0) {
169 march_list.push({name:"_BASEROOM_",known:true,hasnewmsgs:true,floor:0});
172 gotonext(which_oper);
179 // Activate the "Loading..." modal
180 function activate_loading_modal() {
181 document.getElementById("ctdl_big_modal").innerHTML =
182 "<i class=\"fas fa-spinner fa-spin\"></i> "
183 + _("Loading messages from server, please wait");
184 document.getElementById("ctdl_big_modal").style.display = "block";
188 // Disappear the "Loading..." modal
189 function deactivate_loading_modal() {
190 document.getElementById("ctdl_big_modal").style.display = "none";