diff --git a/src/middleware/header.js b/src/middleware/header.js index e35cc0e333..b9eacca002 100644 --- a/src/middleware/header.js +++ b/src/middleware/header.js @@ -82,6 +82,7 @@ module.exports = function (middleware) { uid: 0, username: '[[global:guest]]', userslug: '', + fullname: '[[global:guest]]', email: '', picture: user.getDefaultAvatar(), status: 'offline', diff --git a/src/posts/user.js b/src/posts/user.js index dd050ddd3e..2ada0b2dd3 100644 --- a/src/posts/user.js +++ b/src/posts/user.js @@ -12,12 +12,21 @@ module.exports = function (Posts) { Posts.getUserInfoForPosts = function (uids, uid, callback) { var groupsMap = {}; var userData; + var userSettings; async.waterfall([ function (next) { - user.getUsersFields(uids, ['uid', 'username', 'fullname', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned', 'status', 'lastonline', 'groupTitle'], next); + async.parallel({ + userData: function (next) { + user.getUsersFields(uids, ['uid', 'username', 'fullname', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned', 'status', 'lastonline', 'groupTitle'], next); + }, + userSettings: function (next) { + user.getMultipleUserSettings(uids, next); + }, + }, next); }, - function (_userData, next) { - userData = _userData; + function (results, next) { + userData = results.userData; + userSettings = results.userSettings; var groupTitles = userData.map(function (userData) { return userData && userData.groupTitle; }).filter(function (groupTitle, index, array) { @@ -38,7 +47,7 @@ module.exports = function (Posts) { } }); - userData.forEach(function (userData) { + userData.forEach(function (userData, index) { userData.uid = userData.uid || 0; userData.username = userData.username || '[[global:guest]]'; userData.userslug = userData.userslug || ''; @@ -48,7 +57,7 @@ module.exports = function (Posts) { userData.picture = userData.picture || ''; userData.status = user.getStatus(userData); userData.signature = validator.escape(String(userData.signature || '')); - userData.fullname = validator.escape(String(userData.fullname || '')); + userData.fullname = userSettings[index].showfullname ? validator.escape(String(userData.fullname || '')) : undefined; if (parseInt(meta.config.hideFullname, 10) === 1) { userData.fullname = undefined; } diff --git a/src/topics.js b/src/topics.js index d4f78801aa..5f744316c0 100644 --- a/src/topics.js +++ b/src/topics.js @@ -115,6 +115,9 @@ Topics.getTopicsByTids = function (tids, uid, callback) { users: function (next) { user.getUsersFields(uids, ['uid', 'username', 'fullname', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned', 'status'], next); }, + userSettings: function (next) { + user.getMultipleUserSettings(uids, next); + }, categories: function (next) { categories.getCategoriesFields(cids, ['cid', 'name', 'slug', 'icon', 'image', 'bgColor', 'color', 'disabled'], next); }, @@ -136,11 +139,11 @@ Topics.getTopicsByTids = function (tids, uid, callback) { }, next); }, function (results, next) { - if (parseInt(meta.config.hideFullname, 10) === 1) { - results.users.forEach(function (user) { + results.users.forEach(function (user, index) { + if (parseInt(meta.config.hideFullname, 10) === 1 || !results.userSettings[index].showfullname) { user.fullname = undefined; - }); - } + } + }); var users = _.zipObject(uids, results.users); var categories = _.zipObject(cids, results.categories); diff --git a/src/user/settings.js b/src/user/settings.js index 6ab1ba6816..1a42222acf 100644 --- a/src/user/settings.js +++ b/src/user/settings.js @@ -12,7 +12,7 @@ var pubsub = require('../pubsub'); var LRU = require('lru-cache'); var cache = LRU({ - max: 1000, + max: 2000, length: function () { return 1; }, maxAge: 1000 * 60 * 60, });