Begin gathering references and message IDs for replies
authorArt Cancro <ajc@citadel.org>
Fri, 10 Dec 2021 23:15:43 +0000 (18:15 -0500)
committerArt Cancro <ajc@citadel.org>
Fri, 10 Dec 2021 23:15:43 +0000 (18:15 -0500)
webcit-ng/forum_view.c
webcit-ng/messages.c
webcit-ng/static/js/view_forum.js

index 97f8a1b28d3fabef5b7b5f9abc7a2e3ca05cc0de..f3a9b585391ce4117b585d2df579a2f779a9dbf4 100644 (file)
@@ -82,6 +82,12 @@ void json_render_one_message(struct http_transaction *h, struct ctdlsession *c,
                else if (!strncasecmp(buf, "subj=", 5)) {
                        JsonObjectAppend(j, NewJsonPlainString(HKEY("subj"), &buf[5], -1));
                }
+               else if (!strncasecmp(buf, "msgn=", 5)) {
+                       JsonObjectAppend(j, NewJsonPlainString(HKEY("msgn"), &buf[5], -1));
+               }
+               else if (!strncasecmp(buf, "wefw=", 5)) {
+                       JsonObjectAppend(j, NewJsonPlainString(HKEY("wefw"), &buf[5], -1));
+               }
        }
 
        if (message_originated_locally) {
index ed88c9970ed2d1764669059347ab5a7e4e153f5d..5ecfc165fdf39d4083aab4db1192a72b03e534cd 100644 (file)
@@ -157,13 +157,15 @@ void dav_put_message(struct http_transaction *h, struct ctdlsession *c, char *eu
                return;
        }
 
-       // Remember, ctdl_printf() appends \n on its own, so we only need \r here.
+       // Remember, ctdl_printf() appends \n on its own, so when adding a CRLF newline, only use \r
+       // Or for a blank line, use ctdl_write() with \r\n
+
        content_type = header_val(h, "Content-type");
        ctdl_printf(c, "Content-type: %s\r", (content_type ? content_type : "application/octet-stream"));
-       ctdl_printf(c, "\r");
+       ctdl_write(c, HKEY("\r\n"));
        ctdl_write(c, h->request_body, h->request_body_length);
        if (h->request_body[h->request_body_length] != '\n') {
-               ctdl_printf(c, "\r");
+               ctdl_write(c, HKEY("\r\n"));
        }
        ctdl_printf(c, "000");
 
index 53c12969e2015f1388e3b9a3d2fb60b507e0be3e..d073b99ee37651ac837c2156ced8fdc36e36f703 100644 (file)
@@ -140,14 +140,14 @@ function forum_render_one(prefix, msgnum, scroll_to) {
                        + "</span>"                                                     // end header info on left side
                        + "<span class=\"ctdl-msg-header-buttons\">"                    // begin buttons on right side
 
-                       + "<span class=\"ctdl-msg-button\">"                            // Reply button FIXME make this work
-                       + "<a href=\"javascript:open_reply_box('"+prefix+"',"+msgnum+",false);\">"
+                       + "<span class=\"ctdl-msg-button\">"                            // Reply
+                       + "<a href=\"javascript:open_reply_box('"+prefix+"',"+msgnum+",false,'"+msg.wefw+"','"+msg.msgn+"');\">"
                        + "<i class=\"fa fa-reply\"></i> " 
                        + _("Reply")
                        + "</a></span>"
 
-                       + "<span class=\"ctdl-msg-button\">"                            // ReplyQuoted , only show in forums FIXME
-                       + "<a href=\"javascript:open_reply_box('"+prefix+"',"+msgnum+",true);\">"
+                       + "<span class=\"ctdl-msg-button\">"                            // ReplyQuoted
+                       + "<a href=\"javascript:open_reply_box('"+prefix+"',"+msgnum+",true,'"+msg.wefw+"','"+msg.msgn+"');\">"
                        + "<i class=\"fa fa-comment\"></i> " 
                        + _("ReplyQuoted")
                        + "</a></span>"
@@ -185,10 +185,34 @@ function forum_render_one(prefix, msgnum, scroll_to) {
 }
 
 
+// Compose a references string using existing references plus the message being replied to
+function compose_references(references, msgid) {
+       if (references.includes("@")) {
+               refs = references + "|";
+       }
+       else {
+               refs = "";
+       }
+       refs += msgid;
+
+       console.log("initial len: " + refs.length);
+       // If the resulting string is too big, we can trim it here
+       while (refs.length > 900) {
+               r = refs.split("|");
+               r.splice(1,1);          // remove the second element so we keep the root
+               refs = r.join("|");
+               console.log("split len: " + refs.length);
+       }
+
+
+       return refs;
+}
+
+
 // Open a reply box directly below a specific message
-function open_reply_box(prefix, msgnum, is_quoted) {
+function open_reply_box(prefix, msgnum, is_quoted, references, msgid) {
        target_div_name = prefix+msgnum;
-       new_div_name = prefix + "_reply_to_" + msgnum;
+       new_div_name = prefix + "reply_to_" + msgnum;
        document.getElementById(target_div_name).outerHTML += "<div id=\"" + new_div_name + "\">reply box put here</div>";
 
        // FIXME - we need to retain the message number being replied to
@@ -238,9 +262,9 @@ function open_reply_box(prefix, msgnum, is_quoted) {
        }
        replybox +=
          "</div><br>"                                                  // end header
-
                                                                        // begin body
        + "<div class=\"ctdl-msg-body\" id=\"ctdl-editor-body\" style=\"padding:5px;\" contenteditable=\"true\">"
+       + "refs: " + compose_references(references,msgid) + "<br>"
        + "\n"                                                          // empty initial content
        + "</div>"                                                      // end body
 
@@ -339,7 +363,7 @@ function forum_save_message(div_name, reply_to_msgnum) {
                                for (var i in headers) {
                                        if (headers[i].startsWith("etag: ")) {
                                                new_msg_num = headers[i].split(" ")[1];
-                                               alert(new_msg_num);
+                                               alert("div_name=" + div_name + " , reply_to_msgnum = " + reply_to_msgnum + " , new_msg_num = " + new_msg_num);
                                        }
                                }
                                document.getElementById(div_name).outerHTML = "";               // close the editor