From 06699112a86ec234083c133aa70e2dbc43d24316 Mon Sep 17 00:00:00 2001 From: "VL.Y" <1560781+vladimiry@users.noreply.github.com> Date: Tue, 21 Nov 2023 09:08:30 +0300 Subject: [PATCH] show "unread" notification on non-"inbox" folders too, #656 * It worked for "local store" mode, but now show works without "local store" mode enabling too. --- src/electron-preload/webview/primary/api/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/electron-preload/webview/primary/api/index.ts b/src/electron-preload/webview/primary/api/index.ts index 896bacc0..e8215e57 100644 --- a/src/electron-preload/webview/primary/api/index.ts +++ b/src/electron-preload/webview/primary/api/index.ts @@ -365,6 +365,15 @@ export function registerApi(providerApi: ProviderApi): void { (() => { const isEventsApiUrl = providerApi._custom_.buildEventsApiUrlTester({entryApiUrl}); const isMessagesCountApiUrl = providerApi._custom_.buildMessagesCountApiUrlTester({entryApiUrl}); + const excludeLabelIdsFromUnreadCalculation = ((excludeIds: string[]) => { + return (labelID: string) => excludeIds.includes(labelID); + })([ + SYSTEM_FOLDER_IDENTIFIERS.Archive, + SYSTEM_FOLDER_IDENTIFIERS.Spam, + SYSTEM_FOLDER_IDENTIFIERS.Trash, + SYSTEM_FOLDER_IDENTIFIERS["All Mail"], + SYSTEM_FOLDER_IDENTIFIERS["Almost All Mail"], + ]); const responseListeners = [ { tester: {test: isMessagesCountApiUrl}, @@ -373,7 +382,7 @@ export function registerApi(providerApi: ProviderApi): void { return; } return Counts - .filter(({LabelID}) => LabelID === SYSTEM_FOLDER_IDENTIFIERS.Inbox) + .filter(({LabelID}) => !excludeLabelIdsFromUnreadCalculation(LabelID)) .reduce((accumulator, item) => accumulator + item.Unread, 0); }, }, @@ -384,7 +393,7 @@ export function registerApi(providerApi: ProviderApi): void { return; } return MessageCounts - .filter(({LabelID}) => LabelID === SYSTEM_FOLDER_IDENTIFIERS.Inbox) + .filter(({LabelID}) => !excludeLabelIdsFromUnreadCalculation(LabelID)) .reduce((accumulator, item) => accumulator + item.Unread, 0); }, },