feat: improve new email notification logic for inbox
This commit is contained in:
+11
-7
@@ -1530,13 +1530,17 @@ export const useEmailStore = create<EmailStore>((set, get) => ({
|
|||||||
|
|
||||||
const currentEmails = get().emails;
|
const currentEmails = get().emails;
|
||||||
|
|
||||||
// Check if there are new emails by comparing the first email ID
|
// Only notify for genuinely new incoming mail in the Inbox.
|
||||||
const currentFirstEmailId = currentEmails[0]?.id;
|
// Without these guards the toast/sound also fires when sending,
|
||||||
const newFirstEmailId = result.emails[0]?.id;
|
// saving drafts, or moving/deleting the top message in any mailbox,
|
||||||
|
// because all of those change the first-email id of the current view.
|
||||||
// If the first email changed, we have a new email - trigger notification
|
const newFirst = result.emails[0];
|
||||||
if (currentFirstEmailId !== newFirstEmailId && result.emails[0]) {
|
if (
|
||||||
get().handleNewEmailNotification(result.emails[0]);
|
newFirst &&
|
||||||
|
mailbox?.role === 'inbox' &&
|
||||||
|
!currentEmails.some(e => e.id === newFirst.id)
|
||||||
|
) {
|
||||||
|
get().handleNewEmailNotification(newFirst);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge the refreshed first page with the existing loaded emails.
|
// Merge the refreshed first page with the existing loaded emails.
|
||||||
|
|||||||
Reference in New Issue
Block a user