From 123764f8b89c1ae1e8d27d9b18997231b3ed441e Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Fri, 1 May 2026 01:55:24 +0200 Subject: [PATCH] feat: improve new email notification logic for inbox --- stores/email-store.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/stores/email-store.ts b/stores/email-store.ts index ce7321d6..98883971 100644 --- a/stores/email-store.ts +++ b/stores/email-store.ts @@ -1530,13 +1530,17 @@ export const useEmailStore = create((set, get) => ({ const currentEmails = get().emails; - // Check if there are new emails by comparing the first email ID - const currentFirstEmailId = currentEmails[0]?.id; - const newFirstEmailId = result.emails[0]?.id; - - // If the first email changed, we have a new email - trigger notification - if (currentFirstEmailId !== newFirstEmailId && result.emails[0]) { - get().handleNewEmailNotification(result.emails[0]); + // Only notify for genuinely new incoming mail in the Inbox. + // Without these guards the toast/sound also fires when sending, + // saving drafts, or moving/deleting the top message in any mailbox, + // because all of those change the first-email id of the current view. + const newFirst = result.emails[0]; + if ( + newFirst && + mailbox?.role === 'inbox' && + !currentEmails.some(e => e.id === newFirst.id) + ) { + get().handleNewEmailNotification(newFirst); } // Merge the refreshed first page with the existing loaded emails.