some cleanup in addUserInfoToPost

v1.18.x
barisusakli 11 years ago
parent b9139ef263
commit e8b89513d4

@ -1,8 +1,19 @@
'use strict';
var db = require('./database'),
var async = require('async'),
path = require('path'),
fs = require('fs'),
nconf = require('nconf'),
validator = require('validator'),
winston = require('winston'),
gravatar = require('gravatar'),
S = require('string'),
db = require('./database'),
utils = require('./../public/src/utils'),
user = require('./user'),
groups = require('./groups'),
topics = require('./topics'),
favourites = require('./favourites'),
postTools = require('./postTools'),
@ -10,20 +21,9 @@ var db = require('./database'),
categories = require('./categories'),
plugins = require('./plugins'),
meta = require('./meta'),
emitter = require('./emitter'),
async = require('async'),
path = require('path'),
fs = require('fs'),
nconf = require('nconf'),
validator = require('validator'),
winston = require('winston'),
gravatar = require('gravatar'),
S = require('string');
emitter = require('./emitter');
(function(Posts) {
var customUserInfo = {};
require('./posts/delete')(Posts);
Posts.create = function(data, callback) {
@ -188,13 +188,13 @@ var db = require('./database'),
});
};
Posts.addUserInfoToPost = function(post, callback) {
Posts.getUserInfoForPost = function(post, callback) {
user.getUserFields(post.uid, ['username', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned'], function(err, userData) {
if (err) {
return callback(err);
}
post.user = {
var userInfo = {
username: userData.username || '[[global:guest]]',
userslug: userData.userslug || '',
reputation: userData.reputation || 0,
@ -203,24 +203,12 @@ var db = require('./database'),
picture: userData.picture || user.createGravatarURLFromEmail('')
};
for (var info in customUserInfo) {
if (customUserInfo.hasOwnProperty(info)) {
post.user[info] = userData[info] || customUserInfo[info];
}
}
async.parallel({
signature: function(next) {
if (parseInt(meta.config.disableSignatures, 10) !== 1) {
return postTools.parseSignature(userData.signature, next);
}
next();
},
editor: function(next) {
if (!post.editor) {
if (parseInt(meta.config.disableSignatures, 10) === 1) {
return next();
}
user.getUserFields(post.editor, ['username', 'userslug'], next);
postTools.parseSignature(userData.signature, next);
},
customProfileInfo: function(next) {
plugins.fireHook('filter:posts.custom_profile_info', {profile: [], uid: post.uid, pid: post.pid}, next);
@ -229,12 +217,10 @@ var db = require('./database'),
if (err) {
return callback(err);
}
post.user.signature = results.signature;
post.editor = results.editor;
post.custom_profile_info = results.profile;
callback(null, post);
userInfo.signature = results.signature;
userInfo.custom_profile_info = results.custom_profile_info;
userInfo.groups = results.groups;
callback(null, userInfo);
});
});
};

@ -224,9 +224,10 @@ module.exports = function(Topics) {
},
function(result, next) {
Topics.pushUnreadCount();
posts.addUserInfoToPost(postData, next);
posts.getUserInfoForPost(postData, next);
},
function(postData, next) {
function(userInfo, next) {
postData.user = userInfo;
Topics.getTopicFields(tid, ['tid', 'title', 'slug'], next);
},
function(topicData, next) {

@ -4,10 +4,11 @@
var async = require('async'),
db = require('./../database'),
emitter = require('./../emitter'),
favourites = require('./../favourites'),
posts = require('./../posts'),
db = require('../database'),
user = require('../user'),
emitter = require('../emitter'),
favourites = require('../favourites'),
posts = require('../posts'),
privileges = require('../privileges');
module.exports = function(Topics) {
@ -45,16 +46,36 @@ module.exports = function(Topics) {
});
async.parallel({
favourites : function(next) {
favourites: function(next) {
favourites.getFavouritesByPostIDs(pids, uid, next);
},
voteData : function(next) {
voteData: function(next) {
favourites.getVoteStatusByPostIDs(pids, uid, next);
},
userData : function(next) {
async.each(postData, posts.addUserInfoToPost, next);
userData: function(next) {
async.each(postData, function(post, next) {
async.parallel({
editor: function(next) {
if (!post.editor) {
return next();
}
user.getUserFields(post.editor, ['username', 'userslug'], next);
},
user: function(next) {
posts.getUserInfoForPost(post, next);
}
}, function(err, results) {
if (err) {
return next(err);
}
post.user = results.user;
post.editor = results.editor;
next();
});
}, next);
},
privileges : function(next) {
privileges: function(next) {
async.map(pids, function (pid, next) {
privileges.posts.get(pid, uid, next);
}, next);

Loading…
Cancel
Save