diff options
author | Pierre de La Morinerie <kemenaran@gmail.com> | 2021-05-21 08:23:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-21 11:53:26 +0530 |
commit | 8ad331d4384a2adf610834340066db4440e92694 (patch) | |
tree | 9f5221681f5938845d345ab26ff46c1248a8a649 /recipes | |
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')
-rw-r--r-- | recipes/mattermost/package.json | 2 | ||||
-rw-r--r-- | recipes/mattermost/webview.js | 18 |
2 files changed, 15 insertions, 5 deletions
diff --git a/recipes/mattermost/package.json b/recipes/mattermost/package.json index 52a1908..f30a0a6 100644 --- a/recipes/mattermost/package.json +++ b/recipes/mattermost/package.json | |||
@@ -1,7 +1,7 @@ | |||
1 | { | 1 | { |
2 | "id": "mattermost", | 2 | "id": "mattermost", |
3 | "name": "Mattermost", | 3 | "name": "Mattermost", |
4 | "version": "1.2.2", | 4 | "version": "1.2.3", |
5 | "description": "Mattermost", | 5 | "description": "Mattermost", |
6 | "main": "index.js", | 6 | "main": "index.js", |
7 | "author": "Stefan Malzner <stefan@adlk.io>", | 7 | "author": "Stefan Malzner <stefan@adlk.io>", |
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); |