Skip to content

Commit

Permalink
rocketchat: fix unread counter disappearing
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0rp committed Jan 4, 2024
1 parent 56ef89a commit 0ffc0c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion recipes/rocketchat/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "rocketchat",
"name": "Rocket.Chat",
"version": "1.4.0",
"version": "1.5.0",
"license": "MIT",
"config": {
"serviceURL": "https://{teamId}.rocket.chat",
Expand Down
24 changes: 12 additions & 12 deletions recipes/rocketchat/webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ const _path = _interopRequireDefault(require('path'));

module.exports = Ferdium => {
const getMessages = () => {
const directMessages = document.querySelectorAll('.rcx-badge');

let directMessagesCount = 0;

for (const directMessage of directMessages) {
directMessagesCount += Ferdium.safeParseInt(directMessage.textContent);
const title = document.querySelector('title');
const matches = title.textContent.match(/^\((\S*?)\)/);

if (matches) {
const count = Ferdium.safeParseInt(matches[1], 10);
if (count) {
Ferdium.setBadge(count);
} else {
Ferdium.setBadge(0, 1);
}
} else {
Ferdium.setBadge(0);
}

const indirectMessagesCount = Math.round(
document.querySelectorAll('.rcx-sidebar-item--highlighted').length,
);

Ferdium.setBadge(directMessagesCount, indirectMessagesCount);
};

Ferdium.loop(getMessages);
Expand Down

0 comments on commit 0ffc0c5

Please sign in to comment.