diff options
Diffstat (limited to 'recipes/nextcloud-talk/webview.js')
-rw-r--r-- | recipes/nextcloud-talk/webview.js | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/recipes/nextcloud-talk/webview.js b/recipes/nextcloud-talk/webview.js index 0c7f5c2..15f4dfb 100644 --- a/recipes/nextcloud-talk/webview.js +++ b/recipes/nextcloud-talk/webview.js | |||
@@ -6,38 +6,46 @@ const _path = _interopRequireDefault(require('path')); | |||
6 | 6 | ||
7 | module.exports = Ferdium => { | 7 | module.exports = Ferdium => { |
8 | const getMessages = () => { | 8 | const getMessages = () => { |
9 | let direct = 0; | 9 | // With `// Legacy ` are marked those selectors that were working for some |
10 | 10 | // Nextcloud version before 27 (24 or 25). | |
11 | const notificationWrapper = document.querySelector( | 11 | const counterBubble = '.counter-bubble__counter'; |
12 | '.notifications .notification-wrapper', | 12 | const directFromLeftSideBar = document.querySelectorAll( |
13 | ); | 13 | `${counterBubble}--highlighted`, // Nextcloud 27 |
14 | 14 | ).length; | |
15 | if (notificationWrapper) { | ||
16 | const directSelector = notificationWrapper.querySelectorAll( | ||
17 | '.notification[object_type="chat"], .notification[object_type="room"]', | ||
18 | ); | ||
19 | direct = directSelector ? Ferdium.safeParseInt(directSelector.length) : 0; | ||
20 | } | ||
21 | |||
22 | let indirect = 0; | 15 | let indirect = 0; |
23 | |||
24 | for (const counter of document.querySelectorAll( | 16 | for (const counter of document.querySelectorAll( |
25 | '.app-navigation-entry__counter', | 17 | '.app-navigation-entry__counter, ' + // Legacy |
18 | `${counterBubble}:not(${counterBubble}--highlighted)`, // Nextcloud 27 | ||
26 | )) { | 19 | )) { |
27 | const entryCounter = counter | 20 | indirect += Ferdium.safeParseInt(counter?.textContent.trim()); |
28 | ? Ferdium.safeParseInt(counter.textContent) | ||
29 | : 0; | ||
30 | indirect += entryCounter; | ||
31 | } | 21 | } |
32 | 22 | ||
33 | if (document.title.startsWith('*')) { | 23 | if (document.title.startsWith('*')) { |
34 | indirect += 1; | 24 | indirect += 1; |
35 | } | 25 | } |
36 | 26 | ||
37 | Ferdium.setBadge(direct, indirect); | 27 | Ferdium.setBadge( |
28 | // Try to use the unread conversations count retrieved from the left | ||
29 | // sidebar, otherwise check Talk specific notifications | ||
30 | directFromLeftSideBar > 0 | ||
31 | ? directFromLeftSideBar | ||
32 | : Ferdium.safeParseInt( | ||
33 | document | ||
34 | .querySelector( | ||
35 | '.notifications .notification-wrapper, ' + // Legacy | ||
36 | '.notification-container .notification-wrapper', // Nextcloud 27 | ||
37 | ) | ||
38 | ?.querySelectorAll( | ||
39 | '.notification[object_type="chat"], ' + // Legacy | ||
40 | '.notification[object_type="room"], ' + // Legacy | ||
41 | '.notification[data-object-type="chat"], ' + // Nextcloud 27 | ||
42 | '.notification[data-object-type="room"]', // Nextcloud 27 | ||
43 | ).length, | ||
44 | ), | ||
45 | indirect, | ||
46 | ); | ||
38 | }; | 47 | }; |
39 | 48 | ||
40 | Ferdium.loop(getMessages); | 49 | Ferdium.loop(getMessages); |
41 | |||
42 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); | 50 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); |
43 | }; | 51 | }; |