From 977ccfbd9e1554ab253dc7d22d8078c46d4dbefb Mon Sep 17 00:00:00 2001 From: Michael Quevillon Date: Wed, 21 Feb 2024 18:55:05 -0600 Subject: [PATCH] Add all unread numbers from chat categories for tray icon --- source/browser/conversation-list.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/source/browser/conversation-list.ts b/source/browser/conversation-list.ts index 755b75c32..186738f26 100644 --- a/source/browser/conversation-list.ts +++ b/source/browser/conversation-list.ts @@ -260,12 +260,20 @@ function countUnread(mutationsList: MutationRecord[]): void { } async function updateTrayIcon(): Promise { - const chatsIcon = await elementReady(selectors.chatsIcon, { - stopOnDomReady: false, - }); + let messageCount = 0; + + await elementReady(selectors.chatsIcon, {stopOnDomReady: false}); + + // Count unread messages in Chats, Marketplace, etc. + for (const element of document.querySelectorAll(selectors.chatsIcon)) { + // Extract messageNumber from ariaLabel + const messageNumber = element?.ariaLabel?.match(/\d+/g); + + if (messageNumber) { + messageCount += parseInt(messageNumber[0]); + } + } - // Extract messageCount from ariaLabel - const messageCount = chatsIcon?.ariaLabel?.match(/\d+/g) ?? 0; ipc.callMain('update-tray-icon', messageCount); }