Skip to content

Commit

Permalink
chore: use frappe.client.delete to delete mail
Browse files Browse the repository at this point in the history
  • Loading branch information
krantheman committed Nov 29, 2024
1 parent 59d55ea commit 4e8d246
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
10 changes: 5 additions & 5 deletions frontend/src/components/Modals/SendMail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
</div>
<div class="mt-2 flex items-center justify-end space-x-2 sm:mt-0">
<Button :label="__('Discard')" @click="discardMail" />
<Button @click="send()" variant="solid" :label="__('Send')" />
<Button @click="send" variant="solid" :label="__('Send')" />
</div>
</div>
</div>
Expand Down Expand Up @@ -286,7 +286,7 @@ const createDraftMail = createResource({
method: 'POST',
makeParams(values) {
return {
// TODO: use display_name
// TODO: use mailbox display_name
from_: `${user.data?.full_name} <${mail.from}>`,
do_not_submit: true,
...mail,
Expand Down Expand Up @@ -317,11 +317,11 @@ const updateDraftMail = createResource({
// TODO: delete using documentresource directly
const deleteDraftMail = createResource({
url: 'mail_client.api.mail.delete_mail',
url: 'frappe.client.delete',
makeParams(values) {
return {
mail_type: 'Outgoing Mail',
mail_id: mailID.value,
doctype: 'Outgoing Mail',
name: mailID.value,
}
},
onSuccess() {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Drafts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const draftMailsCount = createResource({
doctype: 'Outgoing Mail',
filters: {
sender: user.data?.name,
folder: 'Drafts',
status: 'Draft',
},
}
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Sent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const sentMailsCount = createResource({
doctype: 'Outgoing Mail',
filters: {
sender: user.data?.name,
folder: 'Sent',
status: 'Sent',
},
}
},
Expand Down
19 changes: 6 additions & 13 deletions mail_client/api/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,24 @@ def get_incoming_mails(start: int = 0) -> list:

@frappe.whitelist()
def get_sent_mails(start: int = 0) -> list:
"""Returns mails from Sent frolder for the current user."""
"""Returns sent mails for the current user."""

return get_outgoing_mails("Sent", start)


@frappe.whitelist()
def get_draft_mails(start: int = 0) -> list:
"""Returns mails from Drafts folder for the current user."""
"""Returns draft mails for the current user."""

return get_outgoing_mails("Drafts", start)
return get_outgoing_mails("Draft", start)


def get_outgoing_mails(folder: str, start: int = 0) -> list:
def get_outgoing_mails(status: str, start: int = 0) -> list:
"""Returns outgoing mails for the current user."""

mailboxes = get_user_mailboxes(frappe.session.user, "Outgoing")

if folder == "Drafts":
if status == "Draft":
docstatus = 0
order_by = "modified desc"
else:
Expand All @@ -116,7 +116,7 @@ def get_outgoing_mails(folder: str, start: int = 0) -> list:

mails = frappe.get_all(
"Outgoing Mail",
{"sender": ["in", mailboxes], "docstatus": docstatus, "folder": folder},
{"sender": ["in", mailboxes], "docstatus": docstatus, "status": status},
[
"name",
"subject",
Expand Down Expand Up @@ -419,10 +419,3 @@ def update_draft_mail(

if do_submit:
doc.submit()


@frappe.whitelist()
def delete_mail(mail_type: str, mail_id: str):
"""Delete mail."""

frappe.delete_doc(mail_type, mail_id)

0 comments on commit 4e8d246

Please sign in to comment.