From fb98432857928b7c26a196fc2b9020c3a90531d9 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Mon, 24 May 2021 10:59:37 +0530 Subject: Fixing unread count in Messenger --- recipes/messenger/webview.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'recipes/messenger/webview.js') diff --git a/recipes/messenger/webview.js b/recipes/messenger/webview.js index ba7ae31..4efdf8c 100644 --- a/recipes/messenger/webview.js +++ b/recipes/messenger/webview.js @@ -2,9 +2,33 @@ module.exports = Franz => { const getMessages = function getMessages() { - let count = document.querySelectorAll('._5fx8:not(._569x),._1ht3:not(._569x)').length; - const messageRequestsElement = document.querySelector('._5nxf'); + let count = 0 + + let isNotification = /^\((\d+)\)/.test(document.title); + /* + * Notification case for group chats, workaround by tamas646 + * see https://github.com/getferdi/ferdi/issues/1113#issuecomment-783409154 + */ + if (isNotification) { + count = parseInt(/^\((\d+)\)/.exec(document.title)[1]); + } else { + /* + * Notification case for direct messages, workaround by manavortex + * see https://github.com/getferdi/ferdi/issues/1113#issuecomment-846611765 + */ + count = document.querySelectorAll('._5fx8:not(._569x),._1ht3:not(._569x)').length; + if (0 === count) { + count = document.querySelectorAll('.pq6dq46d.is6700om.qu0x051f.esr5mh6w.e9989ue4.r7d6kgcz.s45kfl79.emlxlaya.bkmhp75w.spb7xbtv.cyypbtt7.fwizqjfa').length; + } + if (0 === count) { // might be obsolete, not sure - never ran into this case + count = document.querySelectorAll('[aria-label="Mark as read"]').length; + } + } + /* + * add count of message requests on top of notification counter + */ + const messageRequestsElement = document.querySelector('._5nxf'); if (messageRequestsElement) { count += parseInt(messageRequestsElement.innerHTML, 10); } @@ -31,4 +55,4 @@ module.exports = Franz => { return notification; }); } -}; \ No newline at end of file +}; -- cgit v1.2.3-54-g00ecf