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 --- all.json | 2 +- recipes/messenger/package.json | 2 +- recipes/messenger/webview.js | 30 +++++++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/all.json b/all.json index b1e0ead..057a2c3 100644 --- a/all.json +++ b/all.json @@ -829,7 +829,7 @@ "featured": true, "id": "messenger", "name": "Messenger", - "version": "1.1.0", + "version": "1.1.1", "icons": { "png": "https://cdn.jsdelivr.net/gh/getferdi/recipes/recipes/messenger/icon.png", "svg": "https://cdn.jsdelivr.net/gh/getferdi/recipes/recipes/messenger/icon.svg" diff --git a/recipes/messenger/package.json b/recipes/messenger/package.json index b26d37d..5d93f07 100644 --- a/recipes/messenger/package.json +++ b/recipes/messenger/package.json @@ -1,7 +1,7 @@ { "id": "messenger", "name": "Messenger", - "version": "1.1.0", + "version": "1.1.1", "description": "Facebook Messenger", "main": "index.js", "author": "Stefan Malzner ", 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