diff options
author | 2022-05-15 02:18:13 -0500 | |
---|---|---|
committer | 2022-05-15 02:18:13 -0500 | |
commit | 557dfc26b3e446d7a0329565786c8cedfe3d3b55 (patch) | |
tree | 5d18564cf8ac0c668b9b5d3b13821ffad106642a /recipes/zulip/webview.js | |
parent | docs: add Flying--Dutchman as a contributor for code (#28) [skip ci] (diff) | |
download | ferdium-recipes-557dfc26b3e446d7a0329565786c8cedfe3d3b55.tar.gz ferdium-recipes-557dfc26b3e446d7a0329565786c8cedfe3d3b55.tar.zst ferdium-recipes-557dfc26b3e446d7a0329565786c8cedfe3d3b55.zip |
Fix unread message count for zulip
Diffstat (limited to 'recipes/zulip/webview.js')
-rw-r--r-- | recipes/zulip/webview.js | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/recipes/zulip/webview.js b/recipes/zulip/webview.js index 32cb0aa..1989809 100644 --- a/recipes/zulip/webview.js +++ b/recipes/zulip/webview.js | |||
@@ -1,12 +1,24 @@ | |||
1 | module.exports = Ferdium => { | 1 | module.exports = Ferdium => { |
2 | const getMessages = () => { | 2 | const getMessages = () => { |
3 | const allMessages = Math.round( | 3 | // All unread messages |
4 | document.querySelectorAll( | 4 | const unreadAll = getUnreadCount('top_left_all_messages'); |
5 | '#global_filters .top_left_all_messages .count .value', | 5 | |
6 | )[0].textContent, | 6 | // Private messages |
7 | ); | 7 | const unreadPrivate = getUnreadCount('top_left_private_messages'); |
8 | Ferdium.setBadge(allMessages); | 8 | |
9 | // @ Mentions messages | ||
10 | const unreadMentions = getUnreadCount('top_left_mentions'); | ||
11 | |||
12 | const directMessages = unreadPrivate + unreadMentions; | ||
13 | const indirectMessages = unreadAll - directMessages; | ||
14 | |||
15 | Ferdium.setBadge(directMessages, indirectMessages); | ||
9 | }; | 16 | }; |
10 | 17 | ||
11 | Ferdium.loop(getMessages); | 18 | Ferdium.loop(getMessages); |
19 | |||
20 | function getUnreadCount(eltClassName) { | ||
21 | const elt = document.querySelectorAll(`#global_filters .${eltClassName} .unread_count`)[0]; | ||
22 | return elt == null ? 0 : Ferdium.safeParseInt(elt.textContent); | ||
23 | } | ||
12 | }; | 24 | }; |