diff --git a/src/user/data.js b/src/user/data.js index c1e218613f..09ff2e6d3e 100644 --- a/src/user/data.js +++ b/src/user/data.js @@ -145,25 +145,33 @@ module.exports = function (User) { return await User.getUsersFields(uids, []); }; - User.hidePrivateData = async function (userData, callerUID) { - const _userData = { ...userData }; + User.hidePrivateData = async function (users, callerUID) { + if (!Array.isArray(users)) { + users = [users]; + } - const isSelf = parseInt(callerUID, 10) === parseInt(_userData.uid, 10); const [userSettings, isAdmin, isGlobalModerator] = await Promise.all([ - User.getSettings(_userData.uid), + User.getMultipleUserSettings(users.map(user => user.uid)), User.isAdministrator(callerUID), User.isGlobalModerator(callerUID), ]); - const privilegedOrSelf = isAdmin || isGlobalModerator || isSelf; - if (!privilegedOrSelf && (!userSettings.showemail || meta.config.hideEmail)) { - _userData.email = ''; - } - if (!privilegedOrSelf && (!userSettings.showfullname || meta.config.hideFullname)) { - _userData.fullname = ''; - } + users = await Promise.all(users.map(async (userData, idx) => { + const _userData = { ...userData }; + + const isSelf = parseInt(callerUID, 10) === parseInt(_userData.uid, 10); + const privilegedOrSelf = isAdmin || isGlobalModerator || isSelf; + + if (!privilegedOrSelf && (!userSettings[idx].showemail || meta.config.hideEmail)) { + _userData.email = ''; + } + if (!privilegedOrSelf && (!userSettings[idx].showfullname || meta.config.hideFullname)) { + _userData.fullname = ''; + } + return _userData; + })); - return _userData; + return users.length === 1 ? users.pop() : users; }; async function modifyUserData(users, requestedFields, fieldsToRemove) {