From 6496b91c29378edea7f969988880b23722c7cf24 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 9 Mar 2014 14:02:30 -0400 Subject: [PATCH] closes #1180 --- public/src/forum/footer.js | 6 ++---- src/socket.io/topics.js | 2 +- src/socket.io/user.js | 2 +- src/topics.js | 10 +++++----- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index e866b70cf9..f93277a4b5 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -8,13 +8,11 @@ define(['notifications', 'chat'], function(Notifications, Chat) { Chat.prepareDOM(); translator.prepareDOM(); - function updateUnreadCount(err, tids) { - var count = 0, unreadEl = $('#unread-count'); + function updateUnreadCount(err, count) { + var unreadEl = $('#unread-count'); if (err) { console.warn('Error updating unread count', err); - } else if(tids && tids.length) { - count = tids.length; } unreadEl diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index 80139d2f65..5a82e39402 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -101,7 +101,7 @@ SocketTopics.markAllRead = function(socket, data, callback) { return callback(err); } - index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', null, []); + index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', null, 0); callback(); }); diff --git a/src/socket.io/user.js b/src/socket.io/user.js index 05fa97fcb0..f62e95ccfd 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -214,7 +214,7 @@ SocketUser.getOnlineAnonCount = function(socket, data, callback) { }; SocketUser.getUnreadCount = function(socket, data, callback) { - topics.getUnreadTids(socket.uid, 0, 19, callback); + topics.getTotalUnread(socket.uid, callback); }; SocketUser.getActiveUsers = function(socket, data, callback) { diff --git a/src/topics.js b/src/topics.js index b40201e69a..f4c12f4414 100644 --- a/src/topics.js +++ b/src/topics.js @@ -559,8 +559,8 @@ var async = require('async'), }; Topics.getTotalUnread = function(uid, callback) { - Topics.getUnreadTids(uid, 0, 21, function(err, tids) { - callback(err, {count: tids ? tids.length : 0}); + Topics.getUnreadTids(uid, 0, 20, function(err, tids) { + callback(err, tids ? tids.length : 0); }); }; @@ -574,7 +574,7 @@ var async = require('async'), } async.whilst(function() { - return unreadTids.length < 20 && !done; + return unreadTids.length < 21 && !done; }, function(callback) { Topics.getLatestTids(start, stop, 'month', function(err, tids) { if (err) { @@ -671,8 +671,8 @@ var async = require('async'), }); async.each(uids, function(uid, next) { - Topics.getUnreadTids(uid, 0, 19, function(err, tids) { - websockets.in('uid_' + uid).emit('event:unread.updateCount', null, tids); + Topics.getTotalUnread(uid, function(err, count) { + websockets.in('uid_' + uid).emit('event:unread.updateCount', null, count); next(); }); }, function(err) {