From 01a9d479597a38e8e50d44d5da256690cc73309c Mon Sep 17 00:00:00 2001 From: damencho Date: Tue, 5 Jan 2016 17:22:29 -0600 Subject: [PATCH] Fixes setting custom avatar based on the email and reverts the functionality to set custom avatar links to replace the default gravatars. --- modules/UI/avatar/Avatar.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/modules/UI/avatar/Avatar.js b/modules/UI/avatar/Avatar.js index 699d71931..adaa85f36 100644 --- a/modules/UI/avatar/Avatar.js +++ b/modules/UI/avatar/Avatar.js @@ -1,4 +1,4 @@ -/* global Strophe, APP, MD5, config */ +/* global Strophe, APP, MD5, config, interfaceConfig */ var users = {}; var Avatar = { @@ -46,17 +46,27 @@ var Avatar = { console.error("Get gravatar - id is undefined"); return null; } + + // Default to using gravatar. + var urlPref = 'https://www.gravatar.com/avatar/'; + var urlSuf = "?d=wavatar&size=" + (size || "30"); + + // If we have a real email we will use it for the gravatar and we'll + // use the pre-configured URL if any. Otherwise, it's a random avatar. var email = users[id]; - if (!email) { - console.warn( - "No avatar stored yet for " + id + " - using user id as ID" - ); - email = id; + if (email && email.indexOf('@')) { + id = email; + + if (interfaceConfig.RANDOM_AVATAR_URL_PREFIX) { + urlPref = interfaceConfig.RANDOM_AVATAR_URL_PREFIX; + urlSuf = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX; + } } + if (!config.disableThirdPartyRequests) { - return 'https://www.gravatar.com/avatar/' + + return urlPref + MD5.hexdigest(id.trim().toLowerCase()) + - "?d=wavatar&size=" + (size || "30"); + urlSuf; } else { return 'images/avatar2.png'; }