|
|
|
@ -19,15 +19,9 @@ const intFields = [
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
module.exports = function (User) {
|
|
|
|
|
const iconBackgrounds = [
|
|
|
|
|
'#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3',
|
|
|
|
|
'#009688', '#1b5e20', '#33691e', '#827717', '#e65100', '#ff5722',
|
|
|
|
|
'#795548', '#607d8b',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const fieldWhitelist = [
|
|
|
|
|
'uid', 'username', 'userslug', 'email', 'email:confirmed', 'joindate',
|
|
|
|
|
'lastonline', 'picture', 'fullname', 'location', 'birthday', 'website',
|
|
|
|
|
'lastonline', 'picture', 'icon:bgColor', 'fullname', 'location', 'birthday', 'website',
|
|
|
|
|
'aboutme', 'signature', 'uploadedpicture', 'profileviews', 'reputation',
|
|
|
|
|
'postcount', 'topiccount', 'lastposttime', 'banned', 'banned:expire',
|
|
|
|
|
'status', 'flags', 'followerCount', 'followingCount', 'cover:url',
|
|
|
|
@ -203,9 +197,15 @@ module.exports = function (User) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// User Icons
|
|
|
|
|
if (user.hasOwnProperty('picture') && user.username && parseInt(user.uid, 10) && !meta.config.defaultAvatar) {
|
|
|
|
|
if (requestedFields.includes('picture') && user.username && parseInt(user.uid, 10) && !meta.config.defaultAvatar) {
|
|
|
|
|
const iconBackgrounds = await User.getIconBackgrounds(user.uid);
|
|
|
|
|
let bgColor = await User.getUserField(user.uid, 'icon:bgColor');
|
|
|
|
|
if (!iconBackgrounds.includes(bgColor)) {
|
|
|
|
|
bgColor = Array.prototype.reduce.call(user.username, (cur, next) => cur + next.charCodeAt(), 0);
|
|
|
|
|
bgColor = iconBackgrounds[bgColor % iconBackgrounds.length];
|
|
|
|
|
}
|
|
|
|
|
user['icon:text'] = (user.username[0] || '').toUpperCase();
|
|
|
|
|
user['icon:bgColor'] = iconBackgrounds[Array.prototype.reduce.call(user.username, (cur, next) => cur + next.charCodeAt(), 0) % iconBackgrounds.length];
|
|
|
|
|
user['icon:bgColor'] = bgColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user.hasOwnProperty('joindate')) {
|
|
|
|
@ -272,6 +272,17 @@ module.exports = function (User) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.getIconBackgrounds = async (uid = 0) => {
|
|
|
|
|
let iconBackgrounds = [
|
|
|
|
|
'#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3',
|
|
|
|
|
'#009688', '#1b5e20', '#33691e', '#827717', '#e65100', '#ff5722',
|
|
|
|
|
'#795548', '#607d8b',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
({ iconBackgrounds } = await plugins.hooks.fire('filter:user.iconBackgrounds', { uid, iconBackgrounds }));
|
|
|
|
|
return iconBackgrounds;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
User.getDefaultAvatar = function () {
|
|
|
|
|
if (!meta.config.defaultAvatar) {
|
|
|
|
|
return '';
|
|
|
|
|