refactor: chat/notif counts

This commit is contained in:
Barış Soner Uşaklı
2022-11-30 13:53:08 -05:00
parent 289eca08a3
commit 9d599341d9
2 changed files with 14 additions and 9 deletions

View File

@@ -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 });
});
};

View File

@@ -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