aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/whatsapp
diff options
context:
space:
mode:
authorLibravatar Raphael Jenni <RaphaelJenni@users.noreply.github.com>2022-11-19 10:11:54 +0100
committerLibravatar GitHub <noreply@github.com>2022-11-19 09:11:54 +0000
commit8e2492648b7d320f417ac416106b0baf8568f8ed (patch)
treeaba95729623a2670374cd0e72748a73d009a364c /recipes/whatsapp
parentYahoo Mail Recipe Icon Update (#225) (diff)
downloadferdium-recipes-8e2492648b7d320f417ac416106b0baf8568f8ed.tar.gz
ferdium-recipes-8e2492648b7d320f417ac416106b0baf8568f8ed.tar.zst
ferdium-recipes-8e2492648b7d320f417ac416106b0baf8568f8ed.zip
fix: Use IndexedDB for updating whatsapp unread message count (#240)
Co-authored-by: Victor Bonnelle <victor.bonnelle@protonmail.com>
Diffstat (limited to 'recipes/whatsapp')
-rw-r--r--recipes/whatsapp/package.json2
-rw-r--r--recipes/whatsapp/webview.js64
2 files changed, 38 insertions, 28 deletions
diff --git a/recipes/whatsapp/package.json b/recipes/whatsapp/package.json
index a708db4..e4701a5 100644
--- a/recipes/whatsapp/package.json
+++ b/recipes/whatsapp/package.json
@@ -1,7 +1,7 @@
1{ 1{
2 "id": "whatsapp", 2 "id": "whatsapp",
3 "name": "WhatsApp", 3 "name": "WhatsApp",
4 "version": "3.4.6", 4 "version": "3.4.7",
5 "license": "MIT", 5 "license": "MIT",
6 "config": { 6 "config": {
7 "serviceURL": "https://web.whatsapp.com", 7 "serviceURL": "https://web.whatsapp.com",
diff --git a/recipes/whatsapp/webview.js b/recipes/whatsapp/webview.js
index 77c4ebb..8a5f830 100644
--- a/recipes/whatsapp/webview.js
+++ b/recipes/whatsapp/webview.js
@@ -1,41 +1,51 @@
1const _path = _interopRequireDefault(require('path')); 1const _path = _interopRequireDefault(require('path'));
2 2
3function _interopRequireDefault(obj) { 3function _interopRequireDefault(obj) {
4 return obj && obj.__esModule ? obj : { default: obj }; 4 return obj && obj.__esModule ? obj : {default: obj};
5}
6
7let getMessages = () => {
8 /* stub until db is connected*/
5} 9}
6 10
7module.exports = Ferdium => { 11module.exports = Ferdium => {
8 const getMessages = () => { 12 const request = window.indexedDB.open("model-storage");
9 let count = 0; 13 request.onsuccess = () => {
10 let indirectCount = 0; 14 const db = request.result;
11 15
12 const parentChatElem = [ 16 getMessages = () => {
13 ...document.querySelectorAll('div[aria-label]'), 17 let unreadCount = 0;
14 ].sort((a, b) => (a.offsetHeight < b.offsetHeight ? 1 : -1))[0]; 18 let unreadMutedCount = 0;
15 if (!parentChatElem) { 19
16 return; 20 const txn = db.transaction('chat', 'readonly');
17 } 21 const store = txn.objectStore('chat');
18 22
19 const unreadSpans = parentChatElem.querySelectorAll('span[aria-label]'); 23 const query = store.getAll();
20 for (const unreadElem of unreadSpans) { 24
21 const countValue = Ferdium.safeParseInt(unreadElem.textContent); 25 query.onsuccess = (event) => {
22 if (countValue > 0) { 26 for (const chat of event.target.result) {
23 if ( 27 if (chat.unreadCount > 0) {
24 !unreadElem.parentNode.previousSibling || 28 if (chat.muteExpiration === 0) {
25 unreadElem.parentNode.previousSibling.querySelectorAll( 29 unreadCount += chat.unreadCount;
26 '[data-icon=muted]', 30 } else {
27 ).length === 0 31 unreadMutedCount += chat.unreadCount;
28 ) { 32 }
29 count += countValue; 33 }
30 } else {
31 indirectCount += countValue;
32 } 34 }
33 }
34 }
35 35
36 Ferdium.setBadge(count, indirectCount); 36 Ferdium.setBadge(unreadCount, unreadMutedCount);
37 };
38
39 query.addEventListener('error', (event) => {
40 console.error("Loading data from database failed:", event);
41 })
42 }
37 }; 43 };
38 44
45 request.addEventListener('error', (event) => {
46 console.error("Opening model-storage database failed:", event);
47 })
48
39 // inject webview hacking script 49 // inject webview hacking script
40 Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); 50 Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js'));
41 51