Skip to content

Commit

Permalink
feat: load draft mails with thread
Browse files Browse the repository at this point in the history
  • Loading branch information
krantheman committed Nov 25, 2024
1 parent 1335882 commit 9cfaa8b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
3 changes: 2 additions & 1 deletion frontend/src/components/MailDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
</span>
</div>
</div>
<div class="flex items-center self-start space-x-2">
<div v-if="mail.folder === 'Drafts'"></div>
<div v-else class="flex items-center self-start space-x-2">
<MailDate :datetime="mail.creation" />
<Tooltip :text="__('Reply')">
<Button variant="ghost" @click="openModal('reply', mail)">
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/pages/Drafts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
</Breadcrumbs>
<HeaderActions />
</header>
<div v-if="outgoingMails.data" class="flex h-[calc(100vh-3.2rem)]">
<div v-if="draftMails.data" class="flex h-[calc(100vh-3.2rem)]">
<div
@scroll="loadMoreEmails"
ref="mailSidebar"
class="mailSidebar border-r w-1/3 p-2 sticky top-16 overflow-y-scroll overscroll-contain"
>
<div
v-for="(mail, idx) in outgoingMails.data"
v-for="(mail, idx) in draftMails.data"
@click="openMail(mail)"
class="flex flex-col space-y-1 cursor-pointer"
:class="{ 'bg-gray-200 rounded': mail.name == currentMail }"
Expand All @@ -33,7 +33,7 @@
<div
:class="{
'mx-4 h-[0.25px] border-b border-gray-100':
idx < outgoingMails.data.length - 1,
idx < draftMails.data.length - 1,
}"
></div>
</div>
Expand Down Expand Up @@ -67,13 +67,13 @@ const currentMail = ref(JSON.parse(sessionStorage.getItem('currentOutgoingMail')
onMounted(() => {
socket.on('outgoing_mail_sent', (data) => {
outgoingMails.reload()
draftMails.reload()
outgoingMailCount.reload()
})
})
const outgoingMails = createListResource({
url: 'mail_client.api.mail.get_outgoing_mails',
const draftMails = createListResource({
url: 'mail_client.api.mail.get_draft_mails',
doctype: 'Outgoing Mail',
auto: true,
start: mailStart.value,
Expand Down Expand Up @@ -104,7 +104,7 @@ const outgoingMailCount = createResource({
})
const loadMoreEmails = useDebounceFn(() => {
if (outgoingMails.hasNextPage) outgoingMails.next()
if (draftMails.hasNextPage) outgoingMails.next()
}, 500)
const setCurrentMail = (mail) => {
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 @@ -73,7 +73,7 @@ onMounted(() => {
})
const outgoingMails = createListResource({
url: 'mail_client.api.mail.get_outgoing_mails',
url: 'mail_client.api.mail.get_sent_mails',
doctype: 'Outgoing Mail',
auto: true,
start: mailStart.value,
Expand Down
19 changes: 17 additions & 2 deletions mail_client/api/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,28 @@ def get_incoming_mails(start: int = 0) -> list:


@frappe.whitelist()
def get_outgoing_mails(start: int = 0) -> list:
def get_sent_mails(start: int = 0) -> list:
"""Returns mails from Sent frolder 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."""

return get_outgoing_mails("Drafts", start)


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

mailboxes = get_user_mailboxes(frappe.session.user, "Outgoing")
docstatus = 0 if folder == "Drafts" else 1

mails = frappe.get_all(
"Outgoing Mail",
{"sender": ["in", mailboxes], "docstatus": 1, "folder": "Sent"},
{"sender": ["in", mailboxes], "docstatus": docstatus, "folder": folder},
[
"name",
"subject",
Expand Down Expand Up @@ -291,6 +305,7 @@ def get_mail_details(name: str, type: str, include_all_details: bool = False) ->
"message_id",
"in_reply_to_mail_name",
"in_reply_to_mail_type",
"folder",
]

mail = frappe.db.get_value(type, name, fields, as_dict=1)
Expand Down

0 comments on commit 9cfaa8b

Please sign in to comment.