From c39aa07d6f4412c0d1a45792735d28f3c8b10425 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 29 Oct 2015 16:51:58 -0400 Subject: [PATCH] moved colors out, only create icon if picture is requested --- src/user/data.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/user/data.js b/src/user/data.js index 1f857a113c..a2b0a313e0 100644 --- a/src/user/data.js +++ b/src/user/data.js @@ -9,6 +9,9 @@ var plugins = require('../plugins'); module.exports = function(User) { + var iconBackgrounds = ['#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3', + '#009688', '#1b5e20', '#33691e', '#827717', '#e65100', '#ff5722', '#795548', '#607d8b']; + User.getUserField = function(uid, field, callback) { User.getUserFields(uid, [field], function(err, user) { callback(err, user ? user[field] : null); @@ -115,11 +118,12 @@ module.exports = function(User) { } // User Icons - var backgrounds = ['#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3', '#009688', '#1b5e20', '#33691e', '#827717', '#e65100', '#ff5722', '#795548', '#607d8b']; - user['icon:text'] = (user.username[0] || '').toUpperCase(); - user['icon:bgColor'] = backgrounds[Array.prototype.reduce.call(user.username, function(cur, next) { - return cur + next.charCodeAt(); - }, 0) % backgrounds.length]; + if (user.hasOwnProperty('picture')) { + user['icon:text'] = (user.username[0] || '').toUpperCase(); + user['icon:bgColor'] = iconBackgrounds[Array.prototype.reduce.call(user.username, function(cur, next) { + return cur + next.charCodeAt(); + }, 0) % iconBackgrounds.length]; + } }); plugins.fireHook('filter:users.get', users, callback);