make one socket call to load unread counts

This commit is contained in:
barisusakli
2015-10-20 19:19:50 -04:00
parent 8630196a2d
commit 5e5cafafd0
5 changed files with 27 additions and 23 deletions

View File

@@ -207,6 +207,17 @@ SocketUser.getUnreadChatCount = function(socket, data, callback) {
messaging.getUnreadCount(socket.uid, callback);
};
SocketUser.getUnreadCounts = function(socket, data, callback) {
if (!socket.uid) {
return callback(null, {});
}
async.parallel({
unreadTopicCount: async.apply(topics.getTotalUnread, socket.uid),
unreadChatCount: async.apply(messaging.getUnreadCount, socket.uid),
unreadNotificationCount: async.apply(user.notifications.getUnreadCount, socket.uid)
}, callback);
};
SocketUser.loadMore = function(socket, data, callback) {
if (!data || !data.set || parseInt(data.after, 10) < 0) {
return callback(new Error('[[error:invalid-data]]'));