diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 46febe9396..2010135466 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -310,14 +310,15 @@ ]); - socket.on('api:get_users_in_room', function(users) { - var anonymous = users.anonymous, - usernames = users.usernames, - userslugs = users.userslugs, - usercount = usernames.length; - - for (var i = 0, ii=usercount; i' + usernames[i] + ''; + socket.on('api:get_users_in_room', function(data) { + + var anonymousCount = data.anonymousCount, + users = data.users, + usernames = [], + usercount = users.length; + + for (var i = 0, ii=users.length; i' + users[i].username + ''; } // headexplosion.gif for fun, to see if I could do this in one line of code. feel free to refactor haha @@ -326,8 +327,8 @@ + ((usercount === 2 && anonymous === 0) ? usernames[0] + ' and ' + usernames[1] : '') + ((usercount > 2 && anonymous === 0) ? usernames.join(', ').replace(/,([^,]*)$/, ", and$1") : '') + (usercount > 1 && anonymous > 0 ? usernames.join(', ') : '') - + ((anonymous > 0) ? (usercount > 0 ? ' and ': '') + anonymous + ' guest' + (anonymous > 1 ? 's are': ' is') : '') - + (anonymous === 0 ? (usercount > 1 ? ' are' : ' is') : '') + ' browsing this thread'; + + ((anonymousCount > 0) ? (usercount > 0 ? ' and ': '') + anonymousCount + ' guest' + (anonymousCount > 1 ? 's are': ' is') : '') + + (anonymousCount === 0 ? (usercount > 1 ? ' are' : ' is') : '') + ' browsing this thread'; var activeEl = $('#thread_active_users'); if(activeEl.length) diff --git a/src/categories.js b/src/categories.js index 61c55a0e28..99e08d2d45 100644 --- a/src/categories.js +++ b/src/categories.js @@ -57,11 +57,7 @@ var RDB = require('./redis.js'), function getActiveUsers(next) { user.getMultipleUserFields(active_users, ['username', 'userslug'], function(users) { - var activeUserData = []; - for(var uid in users) { - activeUserData.push(users[uid]); - } - next(null, activeUserData); + next(null, users); }); } @@ -206,15 +202,10 @@ var RDB = require('./redis.js'), Categories.getModerators = function(cid, callback) { RDB.smembers('cid:' + cid + ':moderators', function(err, mods) { - if (mods.length === 0) return callback([]); + if (mods.length === 0) + return callback([]); - user.getMultipleUserFields(mods, ['username'], function(details) { - var moderators = []; - for(u in details) { - if (details.hasOwnProperty(u)) { - moderators.push({ username: details[u].username }); - } - } + user.getMultipleUserFields(mods, ['username'], function(moderators) { callback(moderators); }); }); diff --git a/src/user.js b/src/user.js index e6412d4c5e..43c406090f 100644 --- a/src/user.js +++ b/src/user.js @@ -40,21 +40,27 @@ var utils = require('./../public/src/utils.js'), return; } - var data = {}, - loaded = 0; - uuids = uids.filter(function(value, index, self) { + var returnData = []; + + uuids = uids.filter(function(value, index, self) { return self.indexOf(value) === index; }); - for (var i=0, ii=uuids.length; i