From 57376fc94ac0b06768f13a83276db375c41ffdd5 Mon Sep 17 00:00:00 2001 From: Brian Kendall <7917884+briankendall@users.noreply.github.com> Date: Wed, 11 Oct 2023 10:15:24 -0400 Subject: Fix TheLounge sending notifications for muted channels (#435) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix TheLounge sending notifications for muted channels * Fix lint and CI --------- Co-authored-by: André Oliveira --- recipes/thelounge/package.json | 2 +- recipes/thelounge/webview.js | 69 ++++++++++++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 23 deletions(-) (limited to 'recipes') diff --git a/recipes/thelounge/package.json b/recipes/thelounge/package.json index ef43758..4cf50ed 100644 --- a/recipes/thelounge/package.json +++ b/recipes/thelounge/package.json @@ -1,7 +1,7 @@ { "id": "thelounge", "name": "The Lounge", - "version": "1.4.0", + "version": "1.4.1", "license": "MIT", "config": { "hasCustomUrl": true, diff --git a/recipes/thelounge/webview.js b/recipes/thelounge/webview.js index 9be0862..6062288 100644 --- a/recipes/thelounge/webview.js +++ b/recipes/thelounge/webview.js @@ -30,6 +30,13 @@ function countsOfUnreadMessagesAfterMarker(unreadMarker) { return [unread, unreadHighlighted]; } +function isBadgeInMutedChannel(badgeElement) { + const channelListItem = badgeElement.closest('.channel-list-item'); + return ( + channelListItem === null || channelListItem.classList.contains('is-muted') + ); +} + module.exports = Ferdium => { let unreadMessagesAtLastActivity = 0; let unreadHighlightedMessagesAtLastActivity = 0; @@ -45,6 +52,12 @@ module.exports = Ferdium => { const directElements = document.querySelectorAll('.badge.highlight'); for (const directElement of directElements) { + // Note: muted channels don't have highlighted badges for direct notifications, + // but muted networks do + if (isBadgeInMutedChannel(directElement)) { + continue; + } + if (directElement.textContent.length > 0) { direct += Ferdium.safeParseInt(directElement.textContent); } @@ -54,37 +67,49 @@ module.exports = Ferdium => { const indirectElements = document.querySelectorAll( '.badge:not(.highlight)', ); + for (const indirectElement of indirectElements) { + if (isBadgeInMutedChannel(indirectElement)) { + continue; + } + if (indirectElement.textContent.length > 0) { indirect += 1; } } - const unreadMarkers = document.querySelectorAll('div.unread-marker'); - - if (unreadMarkers.length > 0) { - const counts = countsOfUnreadMessagesAfterMarker(unreadMarkers[0]); - const unread = counts[0]; - const unreadHighlighted = counts[1]; - - if (document.hasFocus()) { - unreadMessagesAtLastActivity = unread; - unreadHighlightedMessagesAtLastActivity = unreadHighlighted; - } + // Only want to count unread messages if the active channel is unmuted + if ( + document.querySelectorAll('.channel-list-item.active:not(.is-muted)') + .length > 0 + ) { + const unreadMarkers = document.querySelectorAll('div.unread-marker'); + + if (unreadMarkers.length > 0) { + const counts = countsOfUnreadMessagesAfterMarker(unreadMarkers[0]); + const unread = counts[0]; + const unreadHighlighted = counts[1]; + + if (document.hasFocus()) { + unreadMessagesAtLastActivity = unread; + unreadHighlightedMessagesAtLastActivity = unreadHighlighted; + } - if (unread > unreadMessagesAtLastActivity) { - if ( - unreadHighlighted > 0 && - unreadHighlighted > unreadHighlightedMessagesAtLastActivity - ) { - direct += unreadHighlighted - unreadHighlightedMessagesAtLastActivity; - } else { - indirect += 1; + if (unread > unreadMessagesAtLastActivity) { + if ( + unreadHighlighted > 0 && + unreadHighlighted > unreadHighlightedMessagesAtLastActivity + ) { + direct += + unreadHighlighted - unreadHighlightedMessagesAtLastActivity; + } else { + indirect += 1; + } } + } else { + unreadMessagesAtLastActivity = 0; + unreadHighlightedMessagesAtLastActivity = 0; } - } else { - unreadMessagesAtLastActivity = 0; - unreadHighlightedMessagesAtLastActivity = 0; } Ferdium.setBadge(direct, indirect); -- cgit v1.2.3-54-g00ecf