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
This commit is contained in:
parent
dad0b84847
commit
41b7267e4e
3 changed files with 60 additions and 8 deletions
|
|
@ -34,7 +34,7 @@ class HiddenBlock extends Block {
|
|||
}
|
||||
}
|
||||
HiddenBlock.blotName = 'hiddenblot';
|
||||
HiddenBlock.tagName = 'DIV';
|
||||
HiddenBlock.tagName = 'SPAN';
|
||||
Quill.register(HiddenBlock, true);
|
||||
|
||||
// image uploader
|
||||
|
|
|
|||
|
|
@ -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('<div data-comment="original-reply">')[0];
|
||||
c.content = c.content.split('<span data-comment="original-reply" class="hidden">Reply To</span>')[0];
|
||||
c.content = frappe.utils.strip_original_content(c.content);
|
||||
|
||||
c.original_content = c.content;
|
||||
|
|
|
|||
|
|
@ -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('<span data-comment="original-reply" class="hidden">Reply To</span>')[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, "<br>");
|
||||
}
|
||||
|
||||
if (this.txt) {
|
||||
if(this.txt) {
|
||||
this.message = this.txt + (this.message ? ("<br><br>" + this.message) : "");
|
||||
} else {
|
||||
// saved draft in localStorage
|
||||
|
|
@ -636,8 +638,50 @@ frappe.views.CommunicationComposer = Class.extend({
|
|||
+ this.real_name + ",</p><!-- salutation-ends --><br>" + (this.message || "");
|
||||
}
|
||||
|
||||
var reply = (this.message || "") + (signature ? ("<br>" + signature) : "");
|
||||
let reply = (this.message || "") + (signature ? ("<br>" + 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 <meta> tags
|
||||
.replace(/<style[\s\S]*<\/style>/g, ''); // // remove <style> tags
|
||||
|
||||
// clip last email for a maximum of 20k characters
|
||||
// to prevent the email content from getting too large
|
||||
if (last_email_content.length > 20 * 1024) {
|
||||
last_email_content += '<div>' + __('Message clipped') + '</div>' + last_email_content;
|
||||
last_email_content = last_email_content.slice(0, 20 * 1024);
|
||||
}
|
||||
|
||||
let communication_date = last_email.communication_date || last_email.creation;
|
||||
content = `
|
||||
<div><br></div>
|
||||
${reply}
|
||||
<div class="ql-collapse" data-collapse="true">
|
||||
<span data-comment='original-reply'>Reply To</span>
|
||||
<blockquote>
|
||||
<p>${__("On {0}, {1} wrote:", [frappe.datetime.global_date_format(communication_date) , last_email.sender])}</p>
|
||||
${last_email_content}
|
||||
</blockquote>
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
content = "<div><br></div>" + reply;
|
||||
}
|
||||
fields.content.set_value(content);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue