mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: spec, only call modifyUser on unique user objects
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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),
|
||||
]);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user