Skip to content

Commit

Permalink
fix: ensure that get_last_email returns the most recent email (#20711)
Browse files Browse the repository at this point in the history
Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
Co-authored-by: Sagar Vora <sagar@resilient.tech>
(cherry picked from commit 4b7c735)

# Conflicts:
#	frappe/public/js/frappe/form/footer/form_timeline.js
  • Loading branch information
uepselon authored and mergify[bot] committed May 4, 2023
1 parent 9c52be4 commit d416159
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions frappe/public/js/frappe/form/footer/form_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ class FormTimeline extends BaseTimeline {
}

get_last_email(from_recipient) {
<<<<<<< HEAD
let last_email = null;
let communications = this.frm.get_docinfo().communications || [];
let email = this.get_recipient();
Expand All @@ -568,8 +569,28 @@ class FormTimeline extends BaseTimeline {
}

});

return last_email;
=======
/**
* Return the latest email communication.
*
* @param {boolean} from_recipient If true, only considers emails where current form's recipient is the sender.
* @returns {object|null} The latest email communication, or null if no communication is found.
*/
>>>>>>> 4b7c73514e (fix: ensure that `get_last_email` returns the most recent email (#20711))

const communications = this.frm.get_docinfo().communications || [];
const recipient = this.get_recipient();

const filtered_records = communications
.filter(
(record) =>
record.communication_type === "Communication" &&
record.communication_medium === "Email" &&
(!from_recipient || record.sender === recipient)
)
.sort((a, b) => b.creation - a.creation);

return filtered_records[0] || null;
}

delete_comment(comment_name) {
Expand Down

0 comments on commit d416159

Please sign in to comment.