From 79ddd4bee344db29e69420c1b6514dbed2a9fa63 Mon Sep 17 00:00:00 2001 From: Edgars Date: Tue, 28 Nov 2023 17:18:13 +0200 Subject: Fix selectors for Nextcloud Talk (#473) Script and CSS was updated to add selectors for the latest Nextcloud (27). Previous selectors were left as is for backwards compatibility. Additionally direct notifications count now is detected by unread conversations count in the left sidebar, using Talk specific notifications as a fallback. --- recipes/nextcloud-talk/webview.js | 50 +++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'recipes/nextcloud-talk/webview.js') 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')); module.exports = Ferdium => { const getMessages = () => { - let direct = 0; - - const notificationWrapper = document.querySelector( - '.notifications .notification-wrapper', - ); - - if (notificationWrapper) { - const directSelector = notificationWrapper.querySelectorAll( - '.notification[object_type="chat"], .notification[object_type="room"]', - ); - direct = directSelector ? Ferdium.safeParseInt(directSelector.length) : 0; - } - + // With `// Legacy ` are marked those selectors that were working for some + // Nextcloud version before 27 (24 or 25). + const counterBubble = '.counter-bubble__counter'; + const directFromLeftSideBar = document.querySelectorAll( + `${counterBubble}--highlighted`, // Nextcloud 27 + ).length; let indirect = 0; - for (const counter of document.querySelectorAll( - '.app-navigation-entry__counter', + '.app-navigation-entry__counter, ' + // Legacy + `${counterBubble}:not(${counterBubble}--highlighted)`, // Nextcloud 27 )) { - const entryCounter = counter - ? Ferdium.safeParseInt(counter.textContent) - : 0; - indirect += entryCounter; + indirect += Ferdium.safeParseInt(counter?.textContent.trim()); } if (document.title.startsWith('*')) { indirect += 1; } - Ferdium.setBadge(direct, indirect); + Ferdium.setBadge( + // Try to use the unread conversations count retrieved from the left + // sidebar, otherwise check Talk specific notifications + directFromLeftSideBar > 0 + ? directFromLeftSideBar + : Ferdium.safeParseInt( + document + .querySelector( + '.notifications .notification-wrapper, ' + // Legacy + '.notification-container .notification-wrapper', // Nextcloud 27 + ) + ?.querySelectorAll( + '.notification[object_type="chat"], ' + // Legacy + '.notification[object_type="room"], ' + // Legacy + '.notification[data-object-type="chat"], ' + // Nextcloud 27 + '.notification[data-object-type="room"]', // Nextcloud 27 + ).length, + ), + indirect, + ); }; Ferdium.loop(getMessages); - Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); }; -- cgit v1.2.3-54-g00ecf