diff --git a/src/messaging/data.js b/src/messaging/data.js index 4e9535f51c..7a99d648c3 100644 --- a/src/messaging/data.js +++ b/src/messaging/data.js @@ -56,7 +56,7 @@ module.exports = function (Messaging) { const users = await user.getUsersFields( messages.map(msg => msg && msg.fromuid), - ['uid', 'username', 'fullname', 'userslug', 'picture', 'status', 'banned'] + ['uid', 'username', 'userslug', 'picture', 'status', 'banned'] ); messages.forEach(function (message, index) { diff --git a/src/posts/summary.js b/src/posts/summary.js index 956555b912..0b4e5c8467 100644 --- a/src/posts/summary.js +++ b/src/posts/summary.js @@ -30,7 +30,7 @@ module.exports = function (Posts) { const tids = _.uniq(posts.map(p => p && p.tid)); const [users, topicsAndCategories] = await Promise.all([ - user.getUsersFields(uids, ['uid', 'username', 'fullname', 'userslug', 'picture', 'status']), + user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture', 'status']), getTopicAndCategories(tids), ]); diff --git a/src/user/data.js b/src/user/data.js index 88e2e3caaf..525ec2ba3c 100644 --- a/src/user/data.js +++ b/src/user/data.js @@ -101,6 +101,10 @@ module.exports = function (User) { if (fields.includes('banned') && !fields.includes('banned:expire')) { addField('banned:expire'); } + + if (fields.includes('username') && !fields.includes('fullname')) { + addField('fullname'); + } } function uidsToUsers(uids, uniqueUids, usersData) { @@ -144,29 +148,21 @@ module.exports = function (User) { ['showfullname'] )); } + const uidToUser = {}; + users.forEach(function (user) { + uidToUser[user.uid] = user; + }); - users = await Promise.all(users.map(async function (user) { + await Promise.all(Object.keys(uidToUser).map(async function (uid) { + const user = uidToUser[uid]; if (!user) { - return user; + return; } db.parseIntFields(user, intFields, requestedFields); if (user.hasOwnProperty('username')) { - let showfullname = parseInt(meta.config.showfullname, 10) === 1; - if (uidToSettings[user.uid]) { - if (parseInt(uidToSettings[user.uid].showfullname, 10) === 0) { - showfullname = false; - } else if (parseInt(uidToSettings[user.uid].showfullname, 10) === 1) { - showfullname = true; - } - } - - user.displayname = validator.escape(String( - meta.config.showFullnameAsDisplayName && showfullname && user.fullname ? - user.fullname : - user.username - )); + parseDisplayName(user, uidToSettings); user.username = validator.escape(user.username ? user.username.toString() : ''); } @@ -232,12 +228,28 @@ module.exports = function (User) { user.banned = false; } } - return user; })); return await plugins.fireHook('filter:users.get', users); } + function parseDisplayName(user, uidToSettings) { + let showfullname = parseInt(meta.config.showfullname, 10) === 1; + if (uidToSettings[user.uid]) { + if (parseInt(uidToSettings[user.uid].showfullname, 10) === 0) { + showfullname = false; + } else if (parseInt(uidToSettings[user.uid].showfullname, 10) === 1) { + showfullname = true; + } + } + + user.displayname = validator.escape(String( + meta.config.showFullnameAsDisplayName && showfullname && user.fullname ? + user.fullname : + user.username + )); + } + function parseGroupTitle(user) { try { user.groupTitleArray = JSON.parse(user.groupTitle);