aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/thelounge
diff options
context:
space:
mode:
authorLibravatar Brian Kendall <7917884+briankendall@users.noreply.github.com>2022-01-05 13:42:56 -0500
committerLibravatar GitHub <noreply@github.com>2022-01-05 19:42:56 +0100
commite8a97c037dd0140222c9dd29e63a346616f29f83 (patch)
treebeff398b31dc670aca573b2d390f0c0e48a6feb8 /recipes/thelounge
parentUpdate featured recipes (diff)
downloadferdium-recipes-e8a97c037dd0140222c9dd29e63a346616f29f83.tar.gz
ferdium-recipes-e8a97c037dd0140222c9dd29e63a346616f29f83.tar.zst
ferdium-recipes-e8a97c037dd0140222c9dd29e63a346616f29f83.zip
Fix notifications, badge, and icon for The Lounge (#812)
Diffstat (limited to 'recipes/thelounge')
-rw-r--r--recipes/thelounge/icon.svg2
-rw-r--r--recipes/thelounge/package.json2
-rw-r--r--recipes/thelounge/webview-unsafe.js7
-rw-r--r--recipes/thelounge/webview.js78
4 files changed, 85 insertions, 4 deletions
diff --git a/recipes/thelounge/icon.svg b/recipes/thelounge/icon.svg
index a989688..f773754 100644
--- a/recipes/thelounge/icon.svg
+++ b/recipes/thelounge/icon.svg
@@ -1 +1 @@
<svg height="512" width="512" xmlns="http://www.w3.org/2000/svg"><path d="M170.542 357.786c-15.944-2.444-31.341-6.704-46.024-12.779l-5.493-2.272-44.78 16.973 15.091-33.515-8.914-7.281C48.552 292.879 31 258.503 31 222.119 31 145.96 108.141 84 202.96 84c66.491 0 124.284 30.47 152.885 74.937 6.45.715 12.819 1.716 19.08 3.013C346.379 107.298 280.133 69 202.96 69 99.705 69 16 137.554 16 222.119c0 42.354 20.999 80.691 54.934 108.411l-25.235 56.04 73.085-27.701c18.762 7.762 39.34 13.007 61.07 15.203a134.688 134.688 0 0 1-9.312-16.286z" fill="#818b9e"/><path d="M492 303.273c0-72.144-71.411-130.629-159.5-130.629S173 231.128 173 303.273s71.411 130.629 159.5 130.629c25.834 0 50.229-5.036 71.813-13.965l62.35 23.633-21.528-47.809C474.085 372.112 492 339.406 492 303.273zm-238.5 31.333c-14.636 0-26.5-11.864-26.5-26.5s11.864-26.5 26.5-26.5 26.5 11.864 26.5 26.5-11.864 26.5-26.5 26.5zm79 0c-14.636 0-26.5-11.864-26.5-26.5s11.864-26.5 26.5-26.5 26.5 11.864 26.5 26.5-11.864 26.5-26.5 26.5zm79 0c-14.636 0-26.5-11.864-26.5-26.5s11.864-26.5 26.5-26.5 26.5 11.864 26.5 26.5-11.864 26.5-26.5 26.5z" fill="#455164"/></svg> \ No newline at end of file <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 386 386"><style>.st1{fill:#ff9e18}.st2{fill:#fff}</style><path fill="#415364" d="M0 0h386v386H0z"/><g transform="translate(0 55)"><path class="st1" d="M320.1 100v76.1c0 .7-.4 1.3-.9 1.6l-65.8 37.7c-.6.3-1.3.3-1.8 0l-66.1-38c-.6-.3-.9-.9-.9-1.6V109c0-.7-.4-1.3-.9-1.6L165.5 97c-1.2-.7-2.8.2-2.8 1.6v84.5c0 3.9 2.1 7.6 5.5 9.5l78.7 45.1c3.4 2 7.6 2 11.1 0l78.4-44.9c3.4-2 5.5-5.6 5.5-9.5V92.7c0-3.9-2.1-7.6-5.5-9.5L258 38.3c-3.4-2-7.6-2-11.1 0l-36.3 20.8c-1.2.7-1.2 2.5 0 3.2l18.2 10.4c.6.3 1.3.3 1.8 0l20.9-12c.6-.3 1.3-.3 1.8 0l65.8 37.7c.7.3 1 .9 1 1.6z"/><ellipse class="st2" cx="289.6" cy="138.4" rx="12.4" ry="12.4"/><ellipse class="st2" cx="249.9" cy="138.4" rx="12.4" ry="12.4"/></g><g transform="translate(0 55)"><path class="st2" d="M64.6 176V99.9c0-.7.4-1.3.9-1.6l65.8-37.7c.6-.3 1.3-.3 1.8 0l66.1 38c.6.3.9.9.9 1.6V167c0 .7.4 1.3.9 1.6l18.1 10.4c1.2.7 2.8-.2 2.8-1.6V92.9c0-3.9-2.1-7.6-5.5-9.5l-78.7-45.1c-3.4-2-7.6-2-11.1 0L48.3 83.1c-3.4 2-5.5 5.6-5.5 9.5v90.6c0 3.9 2.1 7.6 5.5 9.5l78.4 44.9c3.4 2 7.6 2 11.1 0l36.3-20.8c1.2-.7 1.2-2.5 0-3.2l-18.2-10.4c-.6-.3-1.3-.3-1.8 0l-20.9 12c-.6.3-1.3.3-1.8 0l-65.8-37.7c-.6-.2-1-.8-1-1.5z"/><ellipse class="st1" cx="95.2" cy="137.6" rx="12.4" ry="12.4"/><ellipse class="st1" cx="134.9" cy="137.6" rx="12.4" ry="12.4"/></g></svg> \ No newline at end of file
diff --git a/recipes/thelounge/package.json b/recipes/thelounge/package.json
index a3f833b..d7b2632 100644
--- a/recipes/thelounge/package.json
+++ b/recipes/thelounge/package.json
@@ -1,7 +1,7 @@
1{ 1{
2 "id": "thelounge", 2 "id": "thelounge",
3 "name": "The Lounge", 3 "name": "The Lounge",
4 "version": "1.1.2", 4 "version": "1.2.0",
5 "license": "MIT", 5 "license": "MIT",
6 "config": { 6 "config": {
7 "hasCustomUrl": true, 7 "hasCustomUrl": true,
diff --git a/recipes/thelounge/webview-unsafe.js b/recipes/thelounge/webview-unsafe.js
new file mode 100644
index 0000000..3f1358a
--- /dev/null
+++ b/recipes/thelounge/webview-unsafe.js
@@ -0,0 +1,7 @@
1// Monkey patch ServiceWorker.postMessage so that it will actually post a notification in Ferdi:
2
3function newPostMessage(options) {
4 window.ferdi.displayNotification(options.title, options);
5}
6
7ServiceWorker.prototype.postMessage = newPostMessage;
diff --git a/recipes/thelounge/webview.js b/recipes/thelounge/webview.js
index b950e8a..394c867 100644
--- a/recipes/thelounge/webview.js
+++ b/recipes/thelounge/webview.js
@@ -1,17 +1,91 @@
1
2function countsOfUnreadMessagesAfterMarker(unreadMarker) {
3 var children = unreadMarker.parentElement.childNodes;
4 var unread = 0;
5 var unreadHighlighted = 0;
6
7 for(var i = children.length-1; i >= 0; --i) {
8 if (children[i] === unreadMarker) {
9 break;
10 }
11
12 if (children[i].classList === undefined) {
13 continue;
14 }
15
16 if (children[i].classList.contains('msg')) {
17 unread++;
18
19 if (children[i].classList.contains('highlight')) {
20 unreadHighlighted++;
21 }
22 }
23 }
24
25 return [unread, unreadHighlighted];
26}
27
1module.exports = Ferdi => { 28module.exports = Ferdi => {
29 var unreadMessagesAtLastActivity = 0;
30 var unreadHighlightedMessagesAtLastActivity = 0;
31
2 const getMessages = () => { 32 const getMessages = () => {
33 // In order to get a correct tally of unread messages, we must
34 // consider both the badges on the various channels, plus the
35 // number of messages that appear after the 'unread' banner that
36 // appears in the page. In the latter case, we should ignore any
37 // messages that arrived before or while the app has focus.
38
39 let direct = 0;
40 var directElements = document.querySelectorAll('.badge.highlight');
41
42 for (const directElement of directElements) {
43 if (directElement.textContent.length > 0) {
44 direct += Ferdi.safeParseInt(directElement.textContent);
45 }
46 }
47
48 let indirect = 0;
3 const indirectElements = document.querySelectorAll( 49 const indirectElements = document.querySelectorAll(
4 '.badge:not(.highlight)', 50 '.badge:not(.highlight)',
5 ); 51 );
6 const direct = document.querySelectorAll('.badge.highlight').length;
7 let indirect = 0;
8 for (const indirectElement of indirectElements) { 52 for (const indirectElement of indirectElements) {
9 if (indirectElement.textContent.length > 0) { 53 if (indirectElement.textContent.length > 0) {
10 indirect++; 54 indirect++;
11 } 55 }
12 } 56 }
57
58 const unreadMarkers = document.querySelectorAll('div.unread-marker');
59
60 if (unreadMarkers.length > 0) {
61 var counts = countsOfUnreadMessagesAfterMarker(unreadMarkers[0]);
62 var unread = counts[0];
63 var unreadHighlighted = counts[1];
64
65 if (document.hasFocus()) {
66 unreadMessagesAtLastActivity = unread;
67 unreadHighlightedMessagesAtLastActivity = unreadHighlighted;
68 }
69
70 if (unread > unreadMessagesAtLastActivity) {
71 if (unreadHighlighted > 0 && unreadHighlighted > unreadHighlightedMessagesAtLastActivity) {
72 direct += (unreadHighlighted - unreadHighlightedMessagesAtLastActivity);
73 } else {
74 indirect++;
75 }
76 }
77 } else {
78 unreadMessagesAtLastActivity = 0;
79 unreadHighlightedMessagesAtLastActivity = 0;
80 }
81
13 Ferdi.setBadge(direct, indirect); 82 Ferdi.setBadge(direct, indirect);
14 }; 83 };
15 84
16 Ferdi.loop(getMessages); 85 Ferdi.loop(getMessages);
86
87 // We need to monkey patch ServierWorker.postMessage so that notifications
88 // will work, and that needs to be done without context isolation:
89 const path = require('path');
90 Ferdi.injectJSUnsafe(path.join(__dirname, 'webview-unsafe.js'));
17}; 91};