|
|
|
@ -1,41 +1,36 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var async = require('async'),
|
|
|
|
|
validator = require('validator'),
|
|
|
|
|
|
|
|
|
|
db = require('../database'),
|
|
|
|
|
user = require('../user'),
|
|
|
|
|
groups = require('../groups'),
|
|
|
|
|
meta = require('../meta'),
|
|
|
|
|
plugins = require('../plugins');
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var validator = require('validator');
|
|
|
|
|
|
|
|
|
|
var user = require('../user');
|
|
|
|
|
var groups = require('../groups');
|
|
|
|
|
var meta = require('../meta');
|
|
|
|
|
var plugins = require('../plugins');
|
|
|
|
|
|
|
|
|
|
module.exports = function(Posts) {
|
|
|
|
|
|
|
|
|
|
Posts.getUserInfoForPosts = function(uids, uid, callback) {
|
|
|
|
|
var groupsMap = {};
|
|
|
|
|
var userSettings;
|
|
|
|
|
async.parallel({
|
|
|
|
|
groupTitles: function(next) {
|
|
|
|
|
var keys = uids.map(function(uid) {
|
|
|
|
|
return 'user:' + uid + ':settings';
|
|
|
|
|
});
|
|
|
|
|
var userData;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
db.getObjectsFields(keys, ['groupTitle'], next);
|
|
|
|
|
function(next) {
|
|
|
|
|
user.getUsersFields(uids, ['uid', 'username', 'fullname', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned', 'status', 'lastonline', 'groupTitle'], next);
|
|
|
|
|
},
|
|
|
|
|
function (_userSettings, next) {
|
|
|
|
|
userSettings = _userSettings;
|
|
|
|
|
var groupKeys = userSettings.filter(function(userSetting) {
|
|
|
|
|
return userSetting && userSetting.groupTitle;
|
|
|
|
|
}).map(function(userSetting) {
|
|
|
|
|
return userSetting.groupTitle;
|
|
|
|
|
function(_userData, next) {
|
|
|
|
|
userData = _userData;
|
|
|
|
|
var groupTitles = userData.map(function(userData) {
|
|
|
|
|
return userData && userData.groupTitle;
|
|
|
|
|
}).filter(function(groupTitle, index, array) {
|
|
|
|
|
return groupTitle && array.indexOf(groupTitle) === index;
|
|
|
|
|
});
|
|
|
|
|
groups.getGroupsData(groupKeys, next);
|
|
|
|
|
},
|
|
|
|
|
function (groupsData, next) {
|
|
|
|
|
groups.getGroupsData(groupTitles, next);
|
|
|
|
|
}
|
|
|
|
|
], function(err, groupsData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
groupsData.forEach(function(group) {
|
|
|
|
|
if (group && group.userTitleEnabled) {
|
|
|
|
|
groupsMap[group.name] = {
|
|
|
|
@ -47,20 +42,8 @@ module.exports = function(Posts) {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
next(null, userSettings);
|
|
|
|
|
}
|
|
|
|
|
], next);
|
|
|
|
|
},
|
|
|
|
|
userData: function(next) {
|
|
|
|
|
user.getUsersFields(uids, ['uid', 'username', 'fullname', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned', 'status', 'lastonline'], next);
|
|
|
|
|
}
|
|
|
|
|
}, function(err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userData = results.userData;
|
|
|
|
|
userData.forEach(function(userData, i) {
|
|
|
|
|
userData.forEach(function(userData) {
|
|
|
|
|
userData.uid = userData.uid || 0;
|
|
|
|
|
userData.username = userData.username || '[[global:guest]]';
|
|
|
|
|
userData.userslug = userData.userslug || '';
|
|
|
|
@ -69,7 +52,6 @@ module.exports = function(Posts) {
|
|
|
|
|
userData.banned = parseInt(userData.banned, 10) === 1;
|
|
|
|
|
userData.picture = userData.picture || '';
|
|
|
|
|
userData.status = user.getStatus(userData);
|
|
|
|
|
userData.groupTitle = results.groupTitles[i].groupTitle;
|
|
|
|
|
userData.signature = validator.escape(userData.signature || '');
|
|
|
|
|
userData.fullname = validator.escape(userData.fullname || '');
|
|
|
|
|
});
|
|
|
|
@ -77,7 +59,7 @@ module.exports = function(Posts) {
|
|
|
|
|
async.map(userData, function(userData, next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
isMemberOfGroup: function (next) {
|
|
|
|
|
if (!userData.groupTitle) {
|
|
|
|
|
if (!userData.groupTitle || !groupsMap[userData.groupTitle]) {
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
groups.isMember(userData.uid, userData.groupTitle, next);
|
|
|
|
|