updateUnreadCount

This commit is contained in:
barisusakli
2014-09-16 11:06:10 -04:00
parent 22577917da
commit 32257c9b2f
5 changed files with 30 additions and 36 deletions

View File

@@ -156,38 +156,18 @@ module.exports = function(Topics) {
});
}
Topics.pushUnreadCount = function(uids, callback) {
if (typeof callback === 'function') {
return callback(null);
} else {
return null;
Topics.pushUnreadCount = function(uid, callback) {
callback = callback || function() {}:
if (!uid || parseInt(uid, 10) === 0) {
return callback();
}
var websockets = require('./../socket.io');
if (!uids) {
uids = websockets.getConnectedClients();
} else if (!Array.isArray(uids)) {
uids = [uids];
}
uids = uids.filter(function(value) {
return parseInt(value, 10) !== 0;
});
async.eachLimit(uids, 5, function(uid, next) {
Topics.getTotalUnread(uid, function(err, count) {
websockets.in('uid_' + uid).emit('event:unread.updateCount', null, count);
next();
});
}, function(err) {
Topics.getTotalUnread(uid, function(err, count) {
if (err) {
winston.error(err.message);
}
if (callback) {
callback();
return callback(err);
}
require('../socket.io').in('uid_' + uid).emit('event:unread.updateCount', null, count);
callback();
});
};