From 9d599341d9e012d969ca649ff4e4bebc5cb4d94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 30 Nov 2022 13:53:08 -0500 Subject: [PATCH] refactor: chat/notif counts --- public/src/client/header/chat.js | 9 ++++++++- public/src/modules/notifications.js | 14 ++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/public/src/client/header/chat.js b/public/src/client/header/chat.js index d363435cac..8808326bd1 100644 --- a/public/src/client/header/chat.js +++ b/public/src/client/header/chat.js @@ -28,9 +28,16 @@ define('forum/header/chat', ['components', 'hooks'], function (components, hooks socket.on('event:chats.roomRename', onRoomRename); socket.on('event:unread.updateChatCount', function (count) { + const chatIcon = components.get('chat/icon'); + count = Math.max(0, count); + chatIcon.toggleClass('fa-comment', count > 0) + .toggleClass('fa-comment-o', count <= 0); + + const countText = count > 99 ? '99+' : count; components.get('chat/icon') .toggleClass('unread-count', count > 0) - .attr('data-content', count > 99 ? '99+' : count); + .attr('data-content', countText); + components.get('chat/count').toggleClass('hidden', count <= 0).text(countText); hooks.fire('action:chat.updateCount', { count }); }); }; diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index d5e9c9ceb5..f7c104bdc1 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -130,15 +130,13 @@ define('notifications', [ Notifications.updateNotifCount = function (count) { const notifIcon = components.get('notifications/icon'); count = Math.max(0, count); - if (count > 0) { - notifIcon.removeClass('fa-bell-o').addClass('fa-bell'); - } else { - notifIcon.removeClass('fa-bell').addClass('fa-bell-o'); - } + notifIcon.toggleClass('fa-bell', count > 0) + .toggleClass('fa-bell-o', count <= 0); + const countText = count > 99 ? '99+' : count; notifIcon.toggleClass('unread-count', count > 0); - notifIcon.attr('data-content', count > 99 ? '99+' : count); - components.get('notifications/count').toggleClass('hidden', count <= 0).text(count); + notifIcon.attr('data-content', countText); + components.get('notifications/count').toggleClass('hidden', count <= 0).text(countText); const payload = { count: count, updateFavicon: true, @@ -146,7 +144,7 @@ define('notifications', [ hooks.fire('action:notification.updateCount', payload); if (payload.updateFavicon) { - Tinycon.setBubble(count > 99 ? '99+' : count); + Tinycon.setBubble(countText); } if (navigator.setAppBadge) { // feature detection