diff options
Diffstat (limited to 'recipes')
-rw-r--r-- | recipes/thelounge/package.json | 2 | ||||
-rw-r--r-- | recipes/thelounge/webview.js | 69 |
2 files changed, 48 insertions, 23 deletions
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 @@ | |||
1 | { | 1 | { |
2 | "id": "thelounge", | 2 | "id": "thelounge", |
3 | "name": "The Lounge", | 3 | "name": "The Lounge", |
4 | "version": "1.4.0", | 4 | "version": "1.4.1", |
5 | "license": "MIT", | 5 | "license": "MIT", |
6 | "config": { | 6 | "config": { |
7 | "hasCustomUrl": true, | 7 | "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) { | |||
30 | return [unread, unreadHighlighted]; | 30 | return [unread, unreadHighlighted]; |
31 | } | 31 | } |
32 | 32 | ||
33 | function isBadgeInMutedChannel(badgeElement) { | ||
34 | const channelListItem = badgeElement.closest('.channel-list-item'); | ||
35 | return ( | ||
36 | channelListItem === null || channelListItem.classList.contains('is-muted') | ||
37 | ); | ||
38 | } | ||
39 | |||
33 | module.exports = Ferdium => { | 40 | module.exports = Ferdium => { |
34 | let unreadMessagesAtLastActivity = 0; | 41 | let unreadMessagesAtLastActivity = 0; |
35 | let unreadHighlightedMessagesAtLastActivity = 0; | 42 | let unreadHighlightedMessagesAtLastActivity = 0; |
@@ -45,6 +52,12 @@ module.exports = Ferdium => { | |||
45 | const directElements = document.querySelectorAll('.badge.highlight'); | 52 | const directElements = document.querySelectorAll('.badge.highlight'); |
46 | 53 | ||
47 | for (const directElement of directElements) { | 54 | for (const directElement of directElements) { |
55 | // Note: muted channels don't have highlighted badges for direct notifications, | ||
56 | // but muted networks do | ||
57 | if (isBadgeInMutedChannel(directElement)) { | ||
58 | continue; | ||
59 | } | ||
60 | |||
48 | if (directElement.textContent.length > 0) { | 61 | if (directElement.textContent.length > 0) { |
49 | direct += Ferdium.safeParseInt(directElement.textContent); | 62 | direct += Ferdium.safeParseInt(directElement.textContent); |
50 | } | 63 | } |
@@ -54,37 +67,49 @@ module.exports = Ferdium => { | |||
54 | const indirectElements = document.querySelectorAll( | 67 | const indirectElements = document.querySelectorAll( |
55 | '.badge:not(.highlight)', | 68 | '.badge:not(.highlight)', |
56 | ); | 69 | ); |
70 | |||
57 | for (const indirectElement of indirectElements) { | 71 | for (const indirectElement of indirectElements) { |
72 | if (isBadgeInMutedChannel(indirectElement)) { | ||
73 | continue; | ||
74 | } | ||
75 | |||
58 | if (indirectElement.textContent.length > 0) { | 76 | if (indirectElement.textContent.length > 0) { |
59 | indirect += 1; | 77 | indirect += 1; |
60 | } | 78 | } |
61 | } | 79 | } |
62 | 80 | ||
63 | const unreadMarkers = document.querySelectorAll('div.unread-marker'); | 81 | // Only want to count unread messages if the active channel is unmuted |
64 | 82 | if ( | |
65 | if (unreadMarkers.length > 0) { | 83 | document.querySelectorAll('.channel-list-item.active:not(.is-muted)') |
66 | const counts = countsOfUnreadMessagesAfterMarker(unreadMarkers[0]); | 84 | .length > 0 |
67 | const unread = counts[0]; | 85 | ) { |
68 | const unreadHighlighted = counts[1]; | 86 | const unreadMarkers = document.querySelectorAll('div.unread-marker'); |
69 | 87 | ||
70 | if (document.hasFocus()) { | 88 | if (unreadMarkers.length > 0) { |
71 | unreadMessagesAtLastActivity = unread; | 89 | const counts = countsOfUnreadMessagesAfterMarker(unreadMarkers[0]); |
72 | unreadHighlightedMessagesAtLastActivity = unreadHighlighted; | 90 | const unread = counts[0]; |
73 | } | 91 | const unreadHighlighted = counts[1]; |
92 | |||
93 | if (document.hasFocus()) { | ||
94 | unreadMessagesAtLastActivity = unread; | ||
95 | unreadHighlightedMessagesAtLastActivity = unreadHighlighted; | ||
96 | } | ||
74 | 97 | ||
75 | if (unread > unreadMessagesAtLastActivity) { | 98 | if (unread > unreadMessagesAtLastActivity) { |
76 | if ( | 99 | if ( |
77 | unreadHighlighted > 0 && | 100 | unreadHighlighted > 0 && |
78 | unreadHighlighted > unreadHighlightedMessagesAtLastActivity | 101 | unreadHighlighted > unreadHighlightedMessagesAtLastActivity |
79 | ) { | 102 | ) { |
80 | direct += unreadHighlighted - unreadHighlightedMessagesAtLastActivity; | 103 | direct += |
81 | } else { | 104 | unreadHighlighted - unreadHighlightedMessagesAtLastActivity; |
82 | indirect += 1; | 105 | } else { |
106 | indirect += 1; | ||
107 | } | ||
83 | } | 108 | } |
109 | } else { | ||
110 | unreadMessagesAtLastActivity = 0; | ||
111 | unreadHighlightedMessagesAtLastActivity = 0; | ||
84 | } | 112 | } |
85 | } else { | ||
86 | unreadMessagesAtLastActivity = 0; | ||
87 | unreadHighlightedMessagesAtLastActivity = 0; | ||
88 | } | 113 | } |
89 | 114 | ||
90 | Ferdium.setBadge(direct, indirect); | 115 | Ferdium.setBadge(direct, indirect); |