integrated Tinycon lib and actually fixed notification counts... heh.

closed #610
v1.18.x
Julian Lam 11 years ago
parent 5b6f5ebf9d
commit b176629b44

@ -113,6 +113,10 @@
socket.emit('api:notifications.mark_all_read', null, function() { socket.emit('api:notifications.mark_all_read', null, function() {
notifIcon.toggleClass('active', false); notifIcon.toggleClass('active', false);
utils.refreshTitle(); 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 // Update notification icon, if necessary
if (count > 0) { if (count > 0) {
notifIcon.toggleClass('active', true); notifIcon.toggleClass('active', true);
@ -145,10 +149,18 @@
notifIcon.toggleClass('active', false); notifIcon.toggleClass('active', false);
} }
// Update the saved local count
localStorage.setItem('notifications:count', count);
Tinycon.setBubble(localStorage.getItem('notifications:count'));
// Update favicon // Update favicon
Tinycon.setBubble(count); Tinycon.setBubble(count);
}); });
if (localStorage.getItem('notifications:count') !== null) {
Tinycon.setBubble(localStorage.getItem('notifications:count'));
}
socket.on('event:new_notification', function() { socket.on('event:new_notification', function() {
notifIcon.toggleClass('active', true); notifIcon.toggleClass('active', true);
app.alert({ app.alert({
@ -159,6 +171,11 @@
timeout: 2000 timeout: 2000
}); });
utils.refreshTitle(); 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);
}); });

@ -1009,7 +1009,7 @@ var bcrypt = require('bcrypt'),
}); });
}, },
getUnreadCount: function(uid, callback) { 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) { getUnreadByUniqueId: function(uid, uniqueId, callback) {
RDB.zrange('uid:' + uid + ':notifications:unread', 0, -1, function(err, nids) { RDB.zrange('uid:' + uid + ':notifications:unread', 0, -1, function(err, nids) {

@ -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) { socket.on('api:categories.getRecentReplies', function(tid) {
categories.getRecentReplies(tid, 4, function(replies) { categories.getRecentReplies(tid, 4, function(replies) {
socket.emit('api:categories.getRecentReplies', replies); socket.emit('api:categories.getRecentReplies', replies);

Loading…
Cancel
Save