Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get_last_email #20711

Merged
merged 6 commits into from
May 4, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions frappe/public/js/frappe/form/footer/form_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,31 +607,26 @@ class FormTimeline extends BaseTimeline {
});
}

/**
* Return the latest email communication.
*
* @param {boolean} from_recipient If true, only considers emails where the recipient is in the list of senders.
* @returns {object|null} The latest email communication, or null if no communication is found.
*/
get_last_email(from_recipient) {
let last_email = null;
let communications = this.frm.get_docinfo().communications || [];
let email = this.get_recipient();
// REDESIGN TODO: What is this? Check again
communications
.sort((a, b) => (a.creation > b.creation ? -1 : 1))
.forEach((c) => {
if (
c.communication_type === "Communication" &&
c.communication_medium === "Email"
) {
if (from_recipient) {
if (c.sender.indexOf(email) !== -1) {
last_email = c;
return false;
}
} else {
last_email = c;
return false;
}
}
});

return last_email;
const communications = this.frm.get_docinfo().communications || [];
const email = this.get_recipient();

const filteredRecords = communications
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frappe's style of naming should be preferred. I will fix it.

Suggested change
const filteredRecords = communications
const filtered_records = communications

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

return filteredRecords.length > 0 ? filteredRecords[0] : null;
}

delete_comment(comment_name) {
Expand Down
Loading