Skip to content

Node.js based forum software built for the modern web

integrated Tinycon lib and actually fixed notification counts... heh. closed #610

Julian Lamb176629b44a8
diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js
index 3dd72fca29..dcbdf7b23c 100644
--- a/public/src/forum/footer.js
+++ b/public/src/forum/footer.js
@@ -113,6 +113,10 @@
socket.emit('api:notifications.mark_all_read', null, function() {
notifIcon.toggleClass('active', false);
utils.refreshTitle();
+
+ // Update favicon + local count
+ Tinycon.setBubble(0);
+ localStorage.setItem('notifications:count', 0);
});
});
}
@@ -137,7 +141,7 @@
}
});
- socket.emit('api:notifications.getCount', function(count) {
+ socket.emit('api:notifications.getCount', function(err, count) {
// Update notification icon, if necessary
if (count > 0) {
notifIcon.toggleClass('active', true);
@@ -145,10 +149,18 @@
notifIcon.toggleClass('active', false);
}
+ // Update the saved local count
+ localStorage.setItem('notifications:count', count);
+ Tinycon.setBubble(localStorage.getItem('notifications:count'));
+
// Update favicon
Tinycon.setBubble(count);
});
+ if (localStorage.getItem('notifications:count') !== null) {
+ Tinycon.setBubble(localStorage.getItem('notifications:count'));
+ }
+
socket.on('event:new_notification', function() {
notifIcon.toggleClass('active', true);
app.alert({
@@ -159,6 +171,11 @@
timeout: 2000
});
utils.refreshTitle();
+
+ // Update the favicon + local storage
+ var savedCount = parseInt(localStorage.getItem('notifications:count'),10) || 0;
+ localStorage.setItem('notifications:count', savedCount+1);
+ Tinycon.setBubble(savedCount+1);
});
diff --git a/src/user.js b/src/user.js
index bfb312db91..7dd14e2426 100644
--- a/src/user.js
+++ b/src/user.js
@@ -1009,7 +1009,7 @@ var bcrypt = require('bcrypt'),
});
},
getUnreadCount: function(uid, callback) {
- RDB.zcount('uid:' + uid + ':notifications:unread', 0, 10, callback);
+ RDB.zcount('uid:' + uid + ':notifications:unread', -Infinity, Infinity, callback);
},
getUnreadByUniqueId: function(uid, uniqueId, callback) {
RDB.zrange('uid:' + uid + ':notifications:unread', 0, -1, function(err, nids) {
diff --git a/src/websockets.js b/src/websockets.js
index 87eba11946..86bee24cf4 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -669,6 +669,13 @@ websockets.init = function(io) {
});
});
+ socket.on('api:notifications.getCount', function(callback) {
+ console.log('checking uid', uid);
+ user.notifications.getUnreadCount(uid, function(err, count) {
+ callback(err ? err.message : null, count);
+ });
+ });
+
socket.on('api:categories.getRecentReplies', function(tid) {
categories.getRecentReplies(tid, 4, function(replies) {
socket.emit('api:categories.getRecentReplies', replies);