From 41b7267e4e58d06ad2e0bc8e19fffcd39989d51b Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 11 Dec 2018 13:40:25 +0530 Subject: [PATCH] fix: Email Reply Behaviour (#6578) * fix: Email Reply Behaviour - Now email will be appended to the next reply but it would be clipped at 20k characters. - The reply part of the email would not be shown in the timeline. - If the email is composed using the "New Email", the last email is not appended to the email * fix: Convert into multiline string * fix: var to let * fix: var to let --- .../js/frappe/form/controls/text_editor.js | 2 +- .../public/js/frappe/form/footer/timeline.js | 14 +++-- .../public/js/frappe/views/communication.js | 52 +++++++++++++++++-- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/frappe/public/js/frappe/form/controls/text_editor.js b/frappe/public/js/frappe/form/controls/text_editor.js index 9e27dcf0f8..5203c57e7f 100644 --- a/frappe/public/js/frappe/form/controls/text_editor.js +++ b/frappe/public/js/frappe/form/controls/text_editor.js @@ -34,7 +34,7 @@ class HiddenBlock extends Block { } } HiddenBlock.blotName = 'hiddenblot'; -HiddenBlock.tagName = 'DIV'; +HiddenBlock.tagName = 'SPAN'; Quill.register(HiddenBlock, true); // image uploader diff --git a/frappe/public/js/frappe/form/footer/timeline.js b/frappe/public/js/frappe/form/footer/timeline.js index 83b0f386c3..0782f57b91 100644 --- a/frappe/public/js/frappe/form/footer/timeline.js +++ b/frappe/public/js/frappe/form/footer/timeline.js @@ -78,10 +78,17 @@ frappe.ui.form.Timeline = class Timeline { var selector = this.frm.doctype === "Communication"? ".btn-reply-email": ".btn-new-email"; this.email_button = this.wrapper.find(selector) .on("click", function() { + const $btn = $(this); + let is_a_reply = true; + if ($btn.is('.btn-new-email')) { + is_a_reply = false; + } + var args = { doc: me.frm.doc, frm: me.frm, - recipients: me.get_recipient() + recipients: me.get_recipient(), + is_a_reply } if(me.frm.doctype === "Communication") { @@ -286,7 +293,8 @@ frappe.ui.form.Timeline = class Timeline { txt: "", title: __('Reply'), frm: me.frm, - last_email: last_email + last_email: last_email, + is_a_reply: true }); }); } @@ -336,7 +344,7 @@ frappe.ui.form.Timeline = class Timeline { }); } else { if(c.communication_type=="Communication" && c.communication_medium=="Email") { - c.content = c.content.split('
')[0]; + c.content = c.content.split('')[0]; c.content = frappe.utils.strip_original_content(c.content); c.original_content = c.content; diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js index ec7db29b9d..46f25bc23b 100755 --- a/frappe/public/js/frappe/views/communication.js +++ b/frappe/public/js/frappe/views/communication.js @@ -498,7 +498,9 @@ frappe.views.CommunicationComposer = Class.extend({ save_as_draft: function() { if (this.dialog) { try { - localStorage.setItem(this.frm.doctype + this.frm.docname, this.dialog.get_value('content')); + let message = this.dialog.get_value('content'); + message = message.split('')[0]; + localStorage.setItem(this.frm.doctype + this.frm.docname, message); } catch (e) { // silently fail console.log(e); @@ -621,7 +623,7 @@ frappe.views.CommunicationComposer = Class.extend({ signature = signature.replace(/\n/g, "
"); } - if (this.txt) { + if(this.txt) { this.message = this.txt + (this.message ? ("

" + this.message) : ""); } else { // saved draft in localStorage @@ -636,8 +638,50 @@ frappe.views.CommunicationComposer = Class.extend({ + this.real_name + ",


" + (this.message || ""); } - var reply = (this.message || "") + (signature ? ("
" + signature) : ""); + let reply = (this.message || "") + (signature ? ("
" + signature) : ""); + let content = ''; - fields.content.set_value(reply); + if (this.is_a_reply === 'undefined') { + this.is_a_reply = true; + } + + if (this.is_a_reply) { + let last_email = this.last_email; + + if (!last_email) { + last_email = this.frm && this.frm.timeline.get_last_email(true); + } + + if (!last_email) return; + + let last_email_content = last_email.original_comment || last_email.content; + + last_email_content = last_email_content + .replace(/<meta[\s\S]*meta>/g, '') // remove tags + .replace(/<style[\s\S]*<\/style>/g, ''); // // remove