From: Art Cancro Date: Thu, 30 Nov 2023 19:07:12 +0000 (-1000) Subject: Converting recipient arrays to recipient strings: X-Git-Tag: v997~81 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=407dab1aa8aeed7411e5f15fcbd584822300dcf4 Converting recipient arrays to recipient strings: Fixed the dedupe so it works before now, and also made it DRY. --- diff --git a/webcit-ng/static/js/view_mail.js b/webcit-ng/static/js/view_mail.js index d5673193a..0641bace4 100644 --- a/webcit-ng/static/js/view_mail.js +++ b/webcit-ng/static/js/view_mail.js @@ -152,19 +152,19 @@ function mail_render_one(msgnum, msg, target_div, include_controls) { + "" // end header info on left side + "" // begin buttons on right side - + "" // Reply (mail is always Quoted) + + "" // Reply + "" + " " + _("Reply") + "" - + "" // Reply-All (mail is always Quoted) + + "" // Reply-All + `` + " " + _("ReplyAll") + "" - + "" // Forward (server handles this) + + "" // Forward + "" + " " + _("Forward") @@ -438,6 +438,38 @@ function render_mailbox_display(notify) { } +// helper function for mail_compose() -- converts a recipient array to a string suitable for the To: or Cc: field +function recipient_array_to_string(recps_arr) { + + let returned_string = "" + + if (recps_arr) { + is_reply = 1; + + // first clean up the recipients + for (i=0; i", ">"); + } + + // remove dupes + recps_arr = Array.from(new Set(recps_arr)); + + // now convert it to a string + returned_string = ""; + for (i=0; i 0) { + returned_string += ", "; + } + returned_string += recps_arr[i]; + } + } + + return(returned_string); +} + + + // Compose a new mail message (called by the Reply button here, or by the dispatcher in views.js) // // is_quoted true or false depending on whether the user selected "reply quoted" (is this appropriate for mail?) @@ -451,37 +483,20 @@ function mail_compose(is_quoted, references, quoted_msgnum, m_to, m_cc, m_subjec let is_reply = 0; + console.log(""); + console.log("mail_compose"); + console.log("is_quoted: " + is_quoted); + console.log("references: " + references); + console.log("quoted_msgnum: " + quoted_msgnum); + console.log("m_to: " + m_to); + console.log("m_cc: " + m_cc); + console.log("m_subject: " + m_subject); + // m_to will be an array of zero or more recipients for the To: field. Convert it to a string. - if (m_to) { - is_reply = 1; - m_to = Array.from(new Set(m_to)); // remove dupes - m_to_str = ""; - for (i=0; i 0) { - m_to_str += ", "; - } - m_to_str += m_to[i].replaceAll("<", "<").replaceAll(">", ">"); - } - } - else { - m_to_str = ""; - } + m_to_str = recipient_array_to_string(m_to); - // m_to will be an array of zero or more recipients for the Cc: field. Convert it to a string. - if (m_cc) { - is_reply = 1; - m_cc = Array.from(new Set(m_cc)); // remove dupes - m_cc_str = ""; - for (i=0; i 0) { - m_cc_str += ", "; - } - m_cc_str += m_cc[i].replaceAll("<", "<").replaceAll(">", ">"); - } - } - else { - m_cc_str = ""; - } + // m_cc will be an array of zero or more recipients for the Cc: field. Convert it to a string. + m_cc_str = recipient_array_to_string(m_cc); quoted_div_name = randomString();