|
|
|
@ -12,12 +12,43 @@ var async = require('async'),
|
|
|
|
|
module.exports = function(Posts) {
|
|
|
|
|
|
|
|
|
|
Posts.getUserInfoForPosts = function(uids, uid, callback) {
|
|
|
|
|
var groupsMap = {};
|
|
|
|
|
var userSettings;
|
|
|
|
|
async.parallel({
|
|
|
|
|
groups: function(next) {
|
|
|
|
|
groups.getUserGroups(uids, next);
|
|
|
|
|
groupTitles: function(next) {
|
|
|
|
|
var keys = uids.map(function(uid) {
|
|
|
|
|
return 'user:' + uid + ':settings';
|
|
|
|
|
});
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
db.getObjectsFields(keys, ['groupTitle'], next);
|
|
|
|
|
},
|
|
|
|
|
userSettings: function(next) {
|
|
|
|
|
user.getMultipleUserSettings(uids, next);
|
|
|
|
|
function (_userSettings, next) {
|
|
|
|
|
userSettings = _userSettings;
|
|
|
|
|
var groupKeys = userSettings.filter(function(userSetting) {
|
|
|
|
|
return userSetting && userSetting.groupTitle;
|
|
|
|
|
}).map(function(userSetting) {
|
|
|
|
|
return userSetting.groupTitle;
|
|
|
|
|
}).filter(function(groupTitle, index, array) {
|
|
|
|
|
return groupTitle && array.indexOf(groupTitle) === index;
|
|
|
|
|
});
|
|
|
|
|
groups.getGroupsData(groupKeys, next);
|
|
|
|
|
},
|
|
|
|
|
function (groupsData, next) {
|
|
|
|
|
groupsData.forEach(function(group) {
|
|
|
|
|
if (group && group.userTitleEnabled) {
|
|
|
|
|
groupsMap[group.name] = {
|
|
|
|
|
name: group.name,
|
|
|
|
|
slug: group.slug,
|
|
|
|
|
labelColor: group.labelColor,
|
|
|
|
|
icon: group.icon,
|
|
|
|
|
userTitle: group.userTitle
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
next(null, userSettings);
|
|
|
|
|
}
|
|
|
|
|
], next);
|
|
|
|
|
},
|
|
|
|
|
userData: function(next) {
|
|
|
|
|
user.getUsersFields(uids, ['uid', 'username', 'fullname', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned', 'status', 'lastonline'], next);
|
|
|
|
@ -29,25 +60,6 @@ module.exports = function(Posts) {
|
|
|
|
|
|
|
|
|
|
var userData = results.userData;
|
|
|
|
|
userData.forEach(function(userData, i) {
|
|
|
|
|
userData.groups = [];
|
|
|
|
|
|
|
|
|
|
results.groups[i].forEach(function(group, index) {
|
|
|
|
|
userData.groups[index] = {
|
|
|
|
|
name: group.name,
|
|
|
|
|
slug: group.slug,
|
|
|
|
|
labelColor: group.labelColor,
|
|
|
|
|
icon: group.icon,
|
|
|
|
|
userTitle: group.userTitle
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (results.userSettings[i] && group.name === results.userSettings[i].groupTitle && group.userTitleEnabled) {
|
|
|
|
|
userData.selectedGroup = userData.groups[index];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
userData.status = user.getStatus(userData);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async.map(userData, function(userData, next) {
|
|
|
|
|
userData.uid = userData.uid || 0;
|
|
|
|
|
userData.username = userData.username || '[[global:guest]]';
|
|
|
|
|
userData.userslug = userData.userslug || '';
|
|
|
|
@ -55,8 +67,18 @@ module.exports = function(Posts) {
|
|
|
|
|
userData.postcount = userData.postcount || 0;
|
|
|
|
|
userData.banned = parseInt(userData.banned, 10) === 1;
|
|
|
|
|
userData.picture = userData.picture || '';
|
|
|
|
|
userData.status = user.getStatus(userData);
|
|
|
|
|
userData.groupTitle = results.groupTitles[i].groupTitle;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async.map(userData, function(userData, next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
isMemberOfGroup: function (next) {
|
|
|
|
|
if (!userData.groupTitle) {
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
groups.isMember(userData.uid, userData.groupTitle, next);
|
|
|
|
|
},
|
|
|
|
|
signature: function(next) {
|
|
|
|
|
if (!userData.signature || parseInt(meta.config.disableSignatures, 10) === 1) {
|
|
|
|
|
userData.signature = '';
|
|
|
|
@ -72,6 +94,10 @@ module.exports = function(Posts) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (results.isMemberOfGroup && userData.groupTitle && groupsMap[userData.groupTitle]) {
|
|
|
|
|
userData.selectedGroup = groupsMap[userData.groupTitle];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userData.custom_profile_info = results.customProfileInfo.profile;
|
|
|
|
|
userData.signature = sanitizeSignature(userData.signature);
|
|
|
|
|
|
|
|
|
|