From 1391bd57d041e91b53c09cd297d7774762699d88 Mon Sep 17 00:00:00 2001 From: Daniel Peukert Date: Thu, 16 Dec 2021 11:52:34 +0100 Subject: Fix Rainloop unread counter (#788) --- recipes/rainloop/webview.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'recipes/rainloop/webview.js') diff --git a/recipes/rainloop/webview.js b/recipes/rainloop/webview.js index 346e51f..0a29849 100644 --- a/recipes/rainloop/webview.js +++ b/recipes/rainloop/webview.js @@ -1,24 +1,25 @@ module.exports = Ferdi => { const getMessages = () => { - let updates = 0; - let inbox = 0; - let full = 0; + let messages = 0; - $('.b-folders-user .ui-droppable').each((i, obj) => { - const countText = $(obj).find('.count').first().html(); - if (typeof countText === 'string' && countText !== '') { - if ($(obj).hasClass('system')) { - if ($(obj).hasClass('i-am-inbox')) { - inbox += Ferdi.safeParseInt(countText); + // Let's only loop through user folders, as all system folders are duplicated there + for (const obj of document.querySelectorAll('.b-folders-user .ui-droppable')) { + const countEl = obj.querySelector('.count'); + const countText = countEl ? countEl.innerHTML : ''; + + if (countText != '') { + if (obj.classList.contains('system')) { + // Only count the Inbox system folder and ignore Archive, Trash, Drafts, Spam, Sent + if (obj.classList.contains('i-am-inbox')) { + messages += Ferdi.safeParseInt(countText); } } else { - updates += Ferdi.safeParseInt(countText); + messages += Ferdi.safeParseInt(countText); } } - }); + } - full = inbox + updates; - Ferdi.setBadge(full); + Ferdi.setBadge(messages); }; Ferdi.loop(getMessages); -- cgit v1.2.3-54-g00ecf