Skip to content

Commit

Permalink
Zulip changed unread locations
Browse files Browse the repository at this point in the history
  • Loading branch information
maxandersen committed Dec 13, 2023
1 parent 0ece08f commit bc021e9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion recipes/zulip/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "zulip",
"name": "Zulip",
"version": "1.3.0",
"version": "1.4.0",
"license": "MIT",
"config": {
"hasNotificationSound": true,
Expand Down
39 changes: 29 additions & 10 deletions recipes/zulip/webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,46 @@ function _interopRequireDefault(obj) {
const _path = _interopRequireDefault(require('path'));

module.exports = Ferdium => {
function getUnreadCount(eltClassName) {
const elt = document.querySelectorAll(
`#global_filters .${eltClassName} .unread_count`,
)[0];
return elt === null ? 0 : Ferdium.safeParseInt(elt.textContent);
function getUnreadMentions() {
const anchorWithMentionHref = document.querySelector(
'a[href*="is/mentioned"]',
);
const unreadCountElement =
anchorWithMentionHref.querySelector('.unread_count');

return unreadCountElement == null
? 0
: Ferdium.safeParseInt(unreadCountElement.textContent);
}

function getUnreadCount(eltId) {
const elt = document.querySelectorAll(`#${eltId} + .unread_count`)[0];
return elt == null ? 0 : Ferdium.safeParseInt(elt.textContent);
}

function getStreamsUnread() {
const streamsHeader = document.querySelector('#streams_header');
const unreadCountElement = streamsHeader.querySelector('.unread_count');

return unreadCountElement == null
? 0
: Ferdium.safeParseInt(unreadCountElement.textContent);
}

//document.querySelector('#show_all_private_messages + .unread_count')
const getMessages = () => {
// All unread messages
const unreadAll = getUnreadCount('top_left_all_messages');
const streamUnread = getStreamsUnread();

// Private messages
const unreadPrivate = getUnreadCount('top_left_private_messages');
const unreadPrivate = getUnreadCount('show_all_private_messages');

// @ Mentions messages
const unreadMentions = getUnreadCount('top_left_mentions');
const unreadMentions = getUnreadMentions();

const directMessages = unreadPrivate + unreadMentions;
const indirectMessages = unreadAll - directMessages;

Ferdium.setBadge(directMessages, indirectMessages);
Ferdium.setBadge(directMessages, streamUnread);
};

Ferdium.loop(getMessages);
Expand Down

0 comments on commit bc021e9

Please sign in to comment.