diff options
author | 2021-05-21 08:23:26 +0200 | |
---|---|---|
committer | 2021-05-21 11:53:26 +0530 | |
commit | 8ad331d4384a2adf610834340066db4440e92694 (patch) | |
tree | 9f5221681f5938845d345ab26ff46c1248a8a649 /recipes/mattermost/webview.js | |
parent | Added new recipe: google-contacts (fixes #487) (diff) | |
download | ferdium-recipes-8ad331d4384a2adf610834340066db4440e92694.tar.gz ferdium-recipes-8ad331d4384a2adf610834340066db4440e92694.tar.zst ferdium-recipes-8ad331d4384a2adf610834340066db4440e92694.zip |
Mattermost: fix unreads count (#519)
* Mattermost: fix unreads count
The "Unread messages" badge was broken for two reasons.
1. Mattermost introduced a new configurable Sidebar, which broke the
selectors used by the recipe.
_Note that the legacy sidebar can still be enabled, and may also_
_be displayed by older Mattermost instances. So for compatibility,_
_the legacy selectors are kept._
2. Direct group messages (direct messages sent to more than one person)
weren't counted at all.
Now these messages are properly counted as direct messages (because
that's how Mattermost UI considers them).
Diffstat (limited to 'recipes/mattermost/webview.js')
-rw-r--r-- | recipes/mattermost/webview.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/recipes/mattermost/webview.js b/recipes/mattermost/webview.js index f348da4..c69c370 100644 --- a/recipes/mattermost/webview.js +++ b/recipes/mattermost/webview.js | |||
@@ -1,13 +1,23 @@ | |||
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | module.exports = Franz => { | 3 | module.exports = Franz => { |
4 | const DIRECT_MESSAGES_INDIVIDUAL = '#sidebar-left .unread-title .DirectChannel__profile-picture'; | ||
5 | const DIRECT_MESSAGES_GROUP = '#sidebar-left .unread-title .status--group'; | ||
6 | const DIRECT_MESSAGES_LEGACY = '.sidebar--left .has-badge .badge'; | ||
7 | const ALL_MESSAGES = '#sidebar-left .unread-title'; | ||
8 | const ALL_MESSAGES_LEGACY = '#sidebar-left .unread-title'; | ||
9 | |||
4 | const getMessages = function getMessages() { | 10 | const getMessages = function getMessages() { |
5 | const directMessages = document.querySelectorAll('.sidebar--left .has-badge .badge').length; | 11 | const directMessagesSelector = [DIRECT_MESSAGES_LEGACY, DIRECT_MESSAGES_INDIVIDUAL, DIRECT_MESSAGES_GROUP].join(', '); |
6 | const allMessages = document.querySelectorAll('.sidebar--left .has-badge').length - directMessages; | 12 | const directMessages = document.querySelectorAll(directMessagesSelector).length; |
7 | const channelMessages = document.querySelectorAll('.sidebar--left .unread-title').length - allMessages; | 13 | |
14 | const allMessagesSelector = [ALL_MESSAGES, ALL_MESSAGES_LEGACY].join(', '); | ||
15 | const allMessages = document.querySelectorAll(allMessagesSelector).length - directMessages; | ||
16 | |||
8 | const teamDirectMessages = document.querySelectorAll('.team-wrapper .team-container .badge').length; | 17 | const teamDirectMessages = document.querySelectorAll('.team-wrapper .team-container .badge').length; |
9 | const teamMessages = document.querySelectorAll('.team-wrapper .unread').length - teamDirectMessages; | 18 | const teamMessages = document.querySelectorAll('.team-wrapper .unread').length - teamDirectMessages; |
10 | Franz.setBadge(directMessages + teamDirectMessages, allMessages + channelMessages + teamMessages); | 19 | |
20 | Franz.setBadge(directMessages + teamDirectMessages, allMessages + teamMessages); | ||
11 | }; | 21 | }; |
12 | 22 | ||
13 | Franz.loop(getMessages); | 23 | Franz.loop(getMessages); |