Skip to content

Node.js based forum software built for the modern web

fixed #3268

Julian Lam0c6b2b122e6c
diff --git a/public/src/client/notifications.js b/public/src/client/notifications.js
index 3d710cafca..2848704541 100644
--- a/public/src/client/notifications.js
+++ b/public/src/client/notifications.js
@@ -2,7 +2,7 @@
/* globals define, socket, app */
-define('forum/notifications', ['components'], function(components) {
+define('forum/notifications', ['components', 'notifications'], function(components, notifs) {
var Notifications = {};
Notifications.init = function() {
@@ -25,6 +25,7 @@ define('forum/notifications', ['components'], function(components) {
}
components.get('notifications/item').removeClass('unread');
+ notifs.updateNotifCount(0);
});
});
};
diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js
index c3a9b984de..bf4313b066 100644
--- a/public/src/modules/notifications.js
+++ b/public/src/modules/notifications.js
@@ -47,7 +47,7 @@ define('notifications', ['sounds', 'translator'], function(sound, translator) {
if (err) {
return app.alertError(err.message);
}
- increaseNotifCount(-1);
+ incrementNotifCount(-1);
});
});
@@ -56,7 +56,7 @@ define('notifications', ['sounds', 'translator'], function(sound, translator) {
if (err) {
app.alertError(err.message);
}
- updateNotifCount(0);
+ Notifications.updateNotifCount(0);
});
});
@@ -73,33 +73,20 @@ define('notifications', ['sounds', 'translator'], function(sound, translator) {
}
liEl.toggleClass('unread');
- increaseNotifCount(unread ? -1 : 1);
+ incrementNotifCount(unread ? -1 : 1);
});
});
- function updateNotifCount(count) {
- if (count > 0) {
- notifIcon.removeClass('fa-bell-o').addClass('fa-bell');
- } else {
- notifIcon.removeClass('fa-bell').addClass('fa-bell-o');
- }
-
- notifIcon.toggleClass('unread-count', count > 0);
- notifIcon.attr('data-content', count > 20 ? '20+' : count);
-
- Tinycon.setBubble(count);
- }
-
- function increaseNotifCount(delta) {
+ function incrementNotifCount(delta) {
var count = parseInt(notifIcon.attr('data-content'), 10) + delta;
- updateNotifCount(count);
+ Notifications.updateNotifCount(count);
}
socket.emit('notifications.getCount', function(err, count) {
if (!err) {
- updateNotifCount(count);
+ Notifications.updateNotifCount(count);
} else {
- updateNotifCount(0);
+ Notifications.updateNotifCount(0);
}
});
@@ -117,15 +104,30 @@ define('notifications', ['sounds', 'translator'], function(sound, translator) {
ajaxify.refresh();
}
- increaseNotifCount(1);
+ incrementNotifCount(1);
sound.play('notification');
});
socket.on('event:notifications.updateCount', function(count) {
- updateNotifCount(count);
+ Notifications.updateNotifCount(count);
});
};
+ Notifications.updateNotifCount = function(count) {
+ var notifIcon = $('.notification-icon');
+
+ if (count > 0) {
+ notifIcon.removeClass('fa-bell-o').addClass('fa-bell');
+ } else {
+ notifIcon.removeClass('fa-bell').addClass('fa-bell-o');
+ }
+
+ notifIcon.toggleClass('unread-count', count > 0);
+ notifIcon.attr('data-content', count > 20 ? '20+' : count);
+
+ Tinycon.setBubble(count);
+ };
+
return Notifications;
});