diff --git a/frappe/core/doctype/comment/comment.py b/frappe/core/doctype/comment/comment.py index 9f5156424f..e4fd181733 100644 --- a/frappe/core/doctype/comment/comment.py +++ b/frappe/core/doctype/comment/comment.py @@ -27,7 +27,8 @@ class Comment(Document): def on_update(self): update_comment_in_doc(self) - self.notify_change('update') + if self.is_new(): + self.notify_change('update') def on_trash(self): self.remove_comment_from_cache() diff --git a/frappe/public/js/frappe/form/footer/form_timeline.js b/frappe/public/js/frappe/form/footer/form_timeline.js index 687433da99..5b3dd29125 100644 --- a/frappe/public/js/frappe/form/footer/form_timeline.js +++ b/frappe/public/js/frappe/form/footer/form_timeline.js @@ -7,7 +7,6 @@ class FormTimeline extends BaseTimeline { make() { super.make(); - this.setup_document_email_link(); this.setup_timeline_actions(); this.render_timeline_items(); this.setup_activity_toggle(); @@ -16,6 +15,7 @@ class FormTimeline extends BaseTimeline { refresh() { super.refresh(); this.frm.trigger('timeline_refresh'); + this.setup_document_email_link(); } setup_timeline_actions() { @@ -70,9 +70,11 @@ class FormTimeline extends BaseTimeline { setup_document_email_link() { let doc_info = this.doc_info || this.frm.get_docinfo(); + this.document_email_link_wrapper && this.document_email_link_wrapper.remove(); + if (doc_info.document_email) { const link = `${doc_info.document_email}`; - const message = __("Send an email to {0} to link it here", [link.bold()]); + const message = __("Add to this activity by mailing to {0}", [link.bold()]); this.document_email_link_wrapper = $(` `); - this.timeline_wrapper.prepend(this.document_email_link_wrapper); + this.timeline_wrapper.append(this.document_email_link_wrapper); this.document_email_link_wrapper .find('.document-email-link') diff --git a/frappe/public/js/frappe/form/form.js b/frappe/public/js/frappe/form/form.js index 916470f023..7dd1468e4c 100644 --- a/frappe/public/js/frappe/form/form.js +++ b/frappe/public/js/frappe/form/form.js @@ -102,7 +102,6 @@ frappe.ui.form.Form = class FrappeForm { } this.setup_file_drop(); this.setup_doctype_actions(); - this.setup_docinfo_change_listener(); this.setup_notify_on_rename(); this.setup_done = true; @@ -369,6 +368,7 @@ frappe.ui.form.Form = class FrappeForm { }); frappe.ui.form.close_grid_form(); this.docname = docname; + this.setup_docinfo_change_listener(); } check_reload() { @@ -1650,10 +1650,15 @@ frappe.ui.form.Form = class FrappeForm { } setup_docinfo_change_listener() { - frappe.realtime.on(`update_docinfo_for_${this.doctype}_${this.docname}`, ({doc, key, action='update'}) => { - let doc_list = (frappe.model.docinfo[this.doctype][this.docname][key] || []); + let doctype = this.doctype; + let docname = this.docname; + let listener_name = `update_docinfo_for_${doctype}_${docname}`; + // to avoid duplicates + frappe.realtime.off(listener_name); + frappe.realtime.on(listener_name, ({doc, key, action='update'}) => { + let doc_list = (frappe.model.docinfo[doctype][docname][key] || []); if (action === 'add') { - frappe.model.docinfo[this.doctype][this.docname][key].push(doc); + frappe.model.docinfo[doctype][docname][key].push(doc); } let docindex = doc_list.findIndex(old_doc => { @@ -1662,10 +1667,10 @@ frappe.ui.form.Form = class FrappeForm { if (docindex > -1) { if (action === 'update') { - frappe.model.docinfo[this.doctype][this.docname][key].splice(docindex, 1, doc); + frappe.model.docinfo[doctype][docname][key].splice(docindex, 1, doc); } if (action === 'delete') { - frappe.model.docinfo[this.doctype][this.docname][key].splice(docindex, 1); + frappe.model.docinfo[doctype][docname][key].splice(docindex, 1); } } // no need to update timeline of owner of comment