|
|
|
@ -370,33 +370,6 @@ var async = require('async'),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getFavouritedUsers(next) {
|
|
|
|
|
favourites.getFavouritedUidsByPids(pids, function(data) {
|
|
|
|
|
var max = 5; //hardcoded
|
|
|
|
|
var usernames = {};
|
|
|
|
|
async.each(pids, function(pid, next) {
|
|
|
|
|
var pid_uids = data[pid];
|
|
|
|
|
var rest_amount = 0;
|
|
|
|
|
if (data.hasOwnProperty(pid) && pid_uids.length > 0) {
|
|
|
|
|
if (pid_uids.length > max) {
|
|
|
|
|
rest_amount = pid_uids.length - max;
|
|
|
|
|
pid_uids = pid_uids.slice(0, max);
|
|
|
|
|
}
|
|
|
|
|
user.getUsernamesByUids(pid_uids, function(result) {
|
|
|
|
|
usernames[pid] = result.join(', ') + (rest_amount > 0
|
|
|
|
|
? " and " + rest_amount + (rest_amount > 1 ? " others" : " other")
|
|
|
|
|
: "");
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
usernames[pid] = [];
|
|
|
|
|
}
|
|
|
|
|
next();
|
|
|
|
|
}, function(err) {
|
|
|
|
|
next(err, usernames);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addUserInfoToPosts(next) {
|
|
|
|
|
function iterator(post, callback) {
|
|
|
|
|
posts.addUserInfoToPost(post, function() {
|
|
|
|
@ -426,19 +399,17 @@ var async = require('async'),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges, getFavouritedUsers], function(err, results) {
|
|
|
|
|
async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges], function(err, results) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var fav_data = results[0],
|
|
|
|
|
privileges = results[2],
|
|
|
|
|
fav_users = results[3];
|
|
|
|
|
privileges = results[2];
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < postData.length; ++i) {
|
|
|
|
|
var pid = postData[i].pid;
|
|
|
|
|
postData[i].favourited = fav_data[pid];
|
|
|
|
|
postData[i].favourited_users = fav_users[pid];
|
|
|
|
|
postData[i].display_moderator_tools = (current_user != 0) && privileges[pid].editable;
|
|
|
|
|
postData[i].display_move_tools = privileges[pid].move ? '' : 'hidden';
|
|
|
|
|
}
|
|
|
|
|