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.
7 // This is called at the very beginning of the main page load.
8 ctdl_startup = async() => {
9 response = await fetch("/ctdl/c/info");
12 serv_info = await(response.json());
13 if (serv_info.serv_rev_level < 905) {
14 alert(_("Citadel server is too old, some functions may not work"));
19 // What do we do upon landing?
21 if ( (serv_info.serv_supports_guest) || (logged_in) ) { // If the Lobby is visible,
22 gotonext(1); // go there.
25 display_login_screen(""); // display the login modal.
29 document.getElementById("ctdl-main").innerHTML =
30 "<div class=\"w3-panel w3-red\"><p>"
31 + _("This program was unable to connect or stay connected to the Citadel server. Please report this problem to your system administrator.")
37 // Display a room list in the main div.
39 // Update the "banner" div with all relevant info.
40 function update_banner() {
43 document.getElementById("ctdl_banner_title").innerHTML = current_room;
45 document.getElementById("ctdl_banner_title").innerHTML += "<i class=\"fa fa-user-cog\"></i>";
47 document.title = current_room;
50 document.getElementById("ctdl_banner_title").innerHTML = serv_info.serv_humannode;
52 document.getElementById("current_user").innerHTML = current_user ;
54 document.getElementById("lilo").innerHTML = "<a href=\"/ctdl/a/logout\"><i class=\"fa fa-right-from-bracket\"></i>" + _("Log off") + "</a>" ;
55 document.getElementById("current_user_avatar").innerHTML = render_userpic(current_user);
58 document.getElementById("lilo").innerHTML = "<a href=\"javascript:display_login_screen('')\"><i class=\"fa fa-right-to-bracket\"></i>" + _("Log in") + "</a>" ;
59 document.getElementById("current_user_avatar").innerHTML = "<i class=\"fa fa-user-circle fa-3x\"></i>";
65 function gotoroom(roomname) {
67 fetch_room = async() => {
68 response = await fetch("/ctdl/r/" + escapeHTMLURI(roomname) + "/");
70 data = await(response.json());
71 current_room = data.name;
72 new_messages = data.new_messages;
73 total_messages = data.total_messages;
74 current_view = data.current_view;
75 default_view = data.default_view;
76 last_seen = data.last_seen;
77 is_room_aide = data.is_room_aide;
78 room_mtime = data.room_mtime;
79 can_delete_messages = data.can_delete_messages;
80 console.log("new mail: " + data.new_mail);
82 render_room_view(0, 9999999999);
89 // Goto next room with unread messages
90 // which_oper is 0=ungoto, 1=skip, 2=goto
91 function gotonext(which_oper) {
92 if (which_oper == 2) { // Goto needs to mark messages as seen
94 set_last_read_pointer = async() => {
95 response = await fetch("/ctdl/r/" + escapeHTMLURI(current_room) + "/slrp?last=" + last_seen);
97 set_last_read_pointer();
100 if ((which_oper == 1) || (which_oper == 2)) { // Skip or Goto both take us to the "next" room
101 if (march_list.length == 0) {
102 load_new_march_list(which_oper); // we will recurse back here
105 next_room = march_list[0].name;
106 march_list.splice(0, 1);
111 // FIXME implement mode 0 (ungoto)
116 // Called by gotonext() when the march list is empty.
117 function load_new_march_list(which_oper) {
118 fetchm = async() => {
119 response = await fetch("/ctdl/r/");
120 march_list = await(response.json());
122 march_list = march_list.filter(function(room) {
123 return room.hasnewmsgs;
125 march_list = march_list.sort(function(a,b) {
126 if (a.floor != b.floor) {
127 return(a.floor - b.floor);
129 if (a.rorder != b.rorder) {
130 return(a.rorder - b.rorder);
132 return(a.name < b.name);
135 // If there are still no rooms with new messages, go to the Lobby.
136 if (march_list.length == 0) {
137 march_list.push({name:"_BASEROOM_",known:true,hasnewmsgs:true,floor:0});
140 gotonext(which_oper);
147 // Activate the "Loading..." modal
148 function activate_loading_modal() {
149 document.getElementById("ctdl_big_modal").innerHTML =
150 "<div class=\"w3-modal-content\">"
151 + " <div class=\"w3-container\">"
153 + "<i class=\"fas fa-spinner fa-spin\"></i> "
154 + _("Loading messages from server, please wait")
158 document.getElementById("ctdl_big_modal").style.display = "block";
162 // Disappear the "Loading..." modal
163 function deactivate_loading_modal() {
164 document.getElementById("ctdl_big_modal").style.display = "none";