fix: spec, only call modifyUser on unique user objects

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 903e9d82b8
commit dbd814c25f

@ -56,7 +56,7 @@ module.exports = function (Messaging) {
const users = await user.getUsersFields( const users = await user.getUsersFields(
messages.map(msg => msg && msg.fromuid), messages.map(msg => msg && msg.fromuid),
['uid', 'username', 'fullname', 'userslug', 'picture', 'status', 'banned'] ['uid', 'username', 'userslug', 'picture', 'status', 'banned']
); );
messages.forEach(function (message, index) { messages.forEach(function (message, index) {

@ -30,7 +30,7 @@ module.exports = function (Posts) {
const tids = _.uniq(posts.map(p => p && p.tid)); const tids = _.uniq(posts.map(p => p && p.tid));
const [users, topicsAndCategories] = await Promise.all([ 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), getTopicAndCategories(tids),
]); ]);

@ -101,6 +101,10 @@ module.exports = function (User) {
if (fields.includes('banned') && !fields.includes('banned:expire')) { if (fields.includes('banned') && !fields.includes('banned:expire')) {
addField('banned:expire'); addField('banned:expire');
} }
if (fields.includes('username') && !fields.includes('fullname')) {
addField('fullname');
}
} }
function uidsToUsers(uids, uniqueUids, usersData) { function uidsToUsers(uids, uniqueUids, usersData) {
@ -144,29 +148,21 @@ module.exports = function (User) {
['showfullname'] ['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) { if (!user) {
return user; return;
} }
db.parseIntFields(user, intFields, requestedFields); db.parseIntFields(user, intFields, requestedFields);
if (user.hasOwnProperty('username')) { if (user.hasOwnProperty('username')) {
let showfullname = parseInt(meta.config.showfullname, 10) === 1; parseDisplayName(user, uidToSettings);
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
));
user.username = validator.escape(user.username ? user.username.toString() : ''); user.username = validator.escape(user.username ? user.username.toString() : '');
} }
@ -232,12 +228,28 @@ module.exports = function (User) {
user.banned = false; user.banned = false;
} }
} }
return user;
})); }));
return await plugins.fireHook('filter:users.get', users); 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) { function parseGroupTitle(user) {
try { try {
user.groupTitleArray = JSON.parse(user.groupTitle); user.groupTitleArray = JSON.parse(user.groupTitle);

Loading…
Cancel
Save