Added the javascript logic to delete a message. This pretty much completes the forum...
authorArt Cancro <ajc@citadel.org>
Thu, 30 Jun 2022 17:56:30 +0000 (13:56 -0400)
committerArt Cancro <ajc@citadel.org>
Thu, 30 Jun 2022 17:56:30 +0000 (13:56 -0400)
webcit-ng/forum_view.c
webcit-ng/static/js/view_forum.js

index ca473f5bd618ca053e04f5b968d9e3ae2e5fc22e..591e5fc55ba673d9bcfc82265fb4f36885424510 100644 (file)
@@ -41,6 +41,7 @@ void json_render_one_message(struct http_transaction *h, struct ctdlsession *c,
        }
 
        JsonValue *j = NewJsonObject(HKEY("message"));
+       JsonObjectAppend(j, NewJsonNumber(HKEY("msgnum"), msgnum));
 
        while ((ctdl_readline(c, buf, sizeof(buf)) >= 0) && (strcmp(buf, "text")) && (strcmp(buf, "000"))) {
 
index cfe9ac61925a60e55f90e54e31f9b9a7f8144e98..febf7f13018c5159e08bf5ebaeccea13d5e4d169 100644 (file)
@@ -204,7 +204,8 @@ function forum_render_one(msg, existing_div) {
        
                if (can_delete_messages) {
                        outmsg +=
-                       "<span class=\"ctdl-msg-button\"><a href=\"#\">"        // Delete (shown only with permission)
+                       "<span class=\"ctdl-msg-button\">"
+                       + "<a href=\"javascript:forum_delete_message('"+mdiv+"','"+msg.msgnum+"');\">"
                        + "<i class=\"fa fa-trash\"></i> " 
                        + _("Delete")
                        + "</a></span>";
@@ -253,6 +254,24 @@ function compose_references(references, msgid) {
        return refs;
 }
 
+// Delete a message.
+// We don't bother checking for permission because the button only appears if we have permission,
+// and even if someone hacks the client, the server will deny any unauthorized deletes.
+function forum_delete_message(message_div, message_number) {
+       if (confirm(_("Delete this message?")) == true) {
+               async_forum_delete_message = async() => {
+                       response = await fetch(
+                               "/ctdl/r/" + escapeHTMLURI(current_room) + "/" + message_number,
+                               { method: "DELETE" }
+                       );
+                       if (response.ok) {              // If the server accepted the delete, blank out the message div.
+                               document.getElementById(message_div).outerHTML = "";
+                       }
+               }
+               async_forum_delete_message();
+       }
+}
+
 
 // Open a reply box directly below a specific message
 function open_reply_box(parent_div, is_quoted, references, msgid) {