Pass through the data to tell the client if it has room aide privileges and/or permis...
authorArt Cancro <ajc@citadel.org>
Wed, 29 Jun 2022 21:17:04 +0000 (17:17 -0400)
committerArt Cancro <ajc@citadel.org>
Wed, 29 Jun 2022 21:17:04 +0000 (17:17 -0400)
webcit-ng/room_functions.c
webcit-ng/static/js/defs.js
webcit-ng/static/js/main.js
webcit-ng/static/js/view_forum.js
webcit-ng/webcit.h

index b6e508c1d426823fd4f807eaaf1d32db641b471a..8944224e9b9271f898d7cca338aa8dacdcd57715 100644 (file)
@@ -425,6 +425,8 @@ void get_the_room_itself(struct http_transaction *h, struct ctdlsession *c) {
        JsonObjectAppend(j, NewJsonPlainString(HKEY("name"), c->room, -1));
        JsonObjectAppend(j, NewJsonNumber(HKEY("current_view"), c->room_current_view));
        JsonObjectAppend(j, NewJsonNumber(HKEY("default_view"), c->room_default_view));
+       JsonObjectAppend(j, NewJsonNumber(HKEY("is_room_aide"), c->is_room_aide));
+       JsonObjectAppend(j, NewJsonNumber(HKEY("can_delete_messages"), c->can_delete_messages));
        JsonObjectAppend(j, NewJsonNumber(HKEY("new_messages"), c->new_messages));
        JsonObjectAppend(j, NewJsonNumber(HKEY("total_messages"), c->total_messages));
        JsonObjectAppend(j, NewJsonNumber(HKEY("last_seen"), c->last_seen));
@@ -525,6 +527,8 @@ void room_list(struct http_transaction *h, struct ctdlsession *c) {
 void ctdl_r(struct http_transaction *h, struct ctdlsession *c) {
        char requested_roomname[128];
        char buf[1024];
+       long room_flags = 0;
+       long room_flags2 = 0;
 
        // All room-related functions require being "in" the room specified.  Are we in that room already?
        extract_token(requested_roomname, h->url, 3, '/', sizeof requested_roomname);
@@ -544,7 +548,7 @@ void ctdl_r(struct http_transaction *h, struct ctdlsession *c) {
                        c->new_messages = extract_int(&buf[4], 1);
                        c->total_messages = extract_int(&buf[4], 2);
                        //      3       (int)info                       Info flag: set to nonzero if the user needs to read this room's info file
-                       //      4       (int)CC->room.QRflags           Various flags associated with this room.
+                       room_flags = extract_long(&buf[4], 3);          // Various flags associated with this room.
                        //      5       (long)CC->room.QRhighest        The highest message number present in this room
                        c->last_seen = extract_long(&buf[4], 6);        // The highest message number the user has read in this room
                        //      7       (int)rmailflag                  Boolean flag: 1 if this is a Mail> room, 0 otherwise.
@@ -554,8 +558,16 @@ void ctdl_r(struct http_transaction *h, struct ctdlsession *c) {
                        c->room_current_view = extract_int(&buf[4], 11);
                        c->room_default_view = extract_int(&buf[4], 12);
                        //      13      (int)is_trash                   Boolean flag: 1 if this is the user's Trash folder, 0 otherwise.
-                       //      14      (int)CC->room.QRflags2          More flags associated with this room
+                       room_flags2 = extract_long(&buf[4], 14);        // More flags associated with this room.
                        //      15      (long)CC->room.QRmtime          Timestamp of the last write activity in this room
+
+                       // If any of these three conditions are met, let the client know it has permission to delete messages.
+                       if ((c->is_room_aide) || (room_flags & QR_MAILBOX) || (room_flags2 & QR2_COLLABDEL)) {
+                               c->can_delete_messages = 1;
+                       }
+                       else {
+                               c->can_delete_messages = 0;
+                       }
                }
                else {
                        do_404(h);
index dfaf7be98f595b46662f58f67ba1f89254d7d3c5..571afc03d7431826fdb3cef4f52694f4947fcf1e 100644 (file)
@@ -19,6 +19,8 @@ var logged_in = 0;
 var current_user = _("Not logged in.");
 var serv_info;
 var last_seen = 0;
+var is_room_aide = 0;
+var can_delete_messages = 0;
 var messages_per_page = 20;
 var march_list = [] ;
 
index 82227708888e20dce50c088f9e656abd60982cb1..20b629a3d403a33c86eda95b21613c130150abc7 100644 (file)
@@ -41,10 +41,10 @@ function update_banner() {
        detect_logged_in();
        if (current_room) {
                document.getElementById("ctdl_banner_title").innerHTML = current_room;
+               if (is_room_aide) {
+                       document.getElementById("ctdl_banner_title").innerHTML += "<i class=\"fa fa-user-cog\"></i>";
+               }
                document.title = current_room;
-
-
-
        }
        else {
                document.getElementById("ctdl_banner_title").innerHTML = serv_info.serv_humannode;
@@ -72,6 +72,8 @@ function gotoroom(roomname) {
                        current_view = data.current_view;
                        default_view = data.default_view;
                        last_seen = data.last_seen;
+                       is_room_aide = data.is_room_aide;
+                       can_delete_messages = data.can_delete_messages;
                        update_banner();
                        render_room_view(0, 9999999999);
                }
index 6840460461419eebc86f25396ff531bacc4fb9eb..cfe9ac61925a60e55f90e54e31f9b9a7f8144e98 100644 (file)
@@ -200,14 +200,18 @@ function forum_render_one(msg, existing_div) {
                + "<a href=\"javascript:open_reply_box('"+mdiv+"',true,'"+msg.wefw+"','"+msg.msgn+"');\">"
                + "<i class=\"fa fa-comment\"></i> " 
                + _("ReplyQuoted")
-               + "</a></span>"
+               + "</a></span>";
        
-               + "<span class=\"ctdl-msg-button\"><a href=\"#\">"              // Delete , show only with permission FIXME
-               + "<i class=\"fa fa-trash\"></i> " 
-               + _("Delete")
-               + "</a></span>"
+               if (can_delete_messages) {
+                       outmsg +=
+                       "<span class=\"ctdl-msg-button\"><a href=\"#\">"        // Delete (shown only with permission)
+                       + "<i class=\"fa fa-trash\"></i> " 
+                       + _("Delete")
+                       + "</a></span>";
+               }
        
-               + "</span>";                                                    // end buttons on right side
+               outmsg +=
+                 "</span>";                                                    // end buttons on right side
                if (msg.subj) {
                        outmsg +=
                        "<br><span class=\"ctdl-msgsubject\">" + msg.subj + "</span>";
index 7e1667a8d3ca7ad611e25e38f3044a1008453763..eeeac89b2bace6f9f84f061d0c5f753c2ab0b299 100644 (file)
@@ -84,6 +84,7 @@ struct ctdlsession {
        int room_current_view;
        int room_default_view;
        int is_room_aide;                       // nonzero if the user has aide rights to THIS room
+       int can_delete_messages;                // nonzeri if the user is permitted to delete messages in THIS room
        long last_seen;
        int new_messages;
        int total_messages;