From 2dcc204502ecbbcac39b667a37ffe36c45f33d6e Mon Sep 17 00:00:00 2001 From: Cornelius <70640137+conny3496@users.noreply.github.com> Date: Sat, 16 Oct 2021 03:40:12 +0200 Subject: fix for #286 with fallback (#738) mostly tested with custom homeserver, not a public matrix server --- recipes/element/webview.js | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/recipes/element/webview.js b/recipes/element/webview.js index 7baa623..771c758 100644 --- a/recipes/element/webview.js +++ b/recipes/element/webview.js @@ -1,22 +1,38 @@ module.exports = Ferdi => { - const getMessages = () => { - const badges = document.querySelectorAll('.mx_RoomSublist:not(.mx_RoomSublist_hidden) .mx_RoomSublist_badgeContainer'); - - // Number of messages from People + function getMessages() { + // const badges = document.querySelectorAll('.mx_RoomSublist:not(.mx_RoomSublist_hidden) .mx_RoomSublist_badgeContainer'); + const spaceBadges = document.querySelectorAll('.mx_SpacePanel_badgeContainer .mx_NotificationBadge .mx_NotificationBadge_count'); + const avatarBadges = document.querySelectorAll('.mx_DecoratedRoomAvatar .mx_NotificationBadge .mx_NotificationBadge_count'); + // Number of messages from People / Number of messages appearing Red in the Room List let directCount = 0; - if (badges.length > 0) { - directCount = Ferdi.safeParseInt(badges[0].textContent); - } - - // Number of messages from Rooms + // Number of messages from Rooms / Number of messages appearing Grey in the Room List let indirectCount = 0; - if (badges.length > 1) { - indirectCount = Ferdi.safeParseInt(badges[1].textContent); + // Count Badges depending on Element Settings + if (avatarBadges.length > 0) { + avatarBadges.forEach(function(badge) { + if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_highlighted')) { + directCount = directCount + Ferdi.safeParseInt(badge.textContent); + } else if (badge.parentElement.previousSibling != null && badge.parentElement.previousSibling.getAttribute('class').includes('mx_DecoratedRoomAvatar_icon_online')) { + directCount = directCount + Ferdi.safeParseInt(badge.textContent); + } else if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_dot')) { + indirectCount = indirectCount + 1; // there might be dragons: incrementing does not work here? + } else { + indirectCount = indirectCount + Ferdi.safeParseInt(badge.textContent); + } + }); + } else { + spaceBadges.forEach(function(badge) { + if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_highlighted')) { + directCount = directCount + Ferdi.safeParseInt(badge.textContent); + } else if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_dot')) { + indirectCount = indirectCount + Ferdi.safeParseInt(1); // there might be dragons: incrementing does not work here? + } else { + indirectCount = indirectCount + Ferdi.safeParseInt(badge.textContent); + } + }); } - // set Ferdi badge Ferdi.setBadge(directCount, indirectCount); } - Ferdi.loop(getMessages); }; -- cgit v1.2.3-70-g09d2