From 057b3000740ad0e0450684e4d818c3d06d959cf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Thu, 4 Oct 2018 15:57:01 +0200 Subject: [PATCH] feat(Participant): reuse avatar URL generation logic It was moved to js-utils, so make use of it. --- package.json | 1 + react/features/base/participants/functions.js | 46 +++++-------------- webpack.config.js | 6 +-- 3 files changed, 16 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index 9e7f26cb1..6211b1541 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "jquery-contextmenu": "2.4.5", "jquery-i18next": "1.2.0", "js-md5": "0.6.1", + "js-utils": "github:jitsi/js-utils#446497893023aa8dec403e0e4e35a22cae6bc87d", "jsc-android": "224109.1.0", "jsrsasign": "8.0.12", "jwt-decode": "2.2.0", diff --git a/react/features/base/participants/functions.js b/react/features/base/participants/functions.js index ea24a6890..e2f4d6970 100644 --- a/react/features/base/participants/functions.js +++ b/react/features/base/participants/functions.js @@ -1,5 +1,5 @@ // @flow -import md5 from 'js-md5'; +import { getAvatarURL as _getAvatarURL } from 'js-utils/avatar'; import { toState } from '../redux'; @@ -42,40 +42,18 @@ export function getAvatarURL({ avatarID, avatarURL, email, id }: { return avatarURL; } - let key = email || avatarID; - let urlPrefix; - let urlSuffix; + // The deployment is allowed to choose the avatar service which is to + // generate the random avatars. + const avatarService + = typeof interfaceConfig === 'object' + && interfaceConfig.RANDOM_AVATAR_URL_PREFIX + ? { + urlPrefix: interfaceConfig.RANDOM_AVATAR_URL_PREFIX, + urlSuffix: interfaceConfig.RANDOM_AVATAR_URL_SUFFIX } + : undefined; - // If the ID looks like an e-mail address, we'll use Gravatar because it - // supports e-mail addresses. - if (key && key.indexOf('@') > 0) { - urlPrefix = 'https://www.gravatar.com/avatar/'; - urlSuffix = '?d=wavatar&size=200'; - } else { - // Otherwise, we do not have much a choice but a random avatar (fetched - // from a configured avatar service). - if (!key) { - key = id; - if (!key) { - return undefined; - } - } - - // The deployment is allowed to choose the avatar service which is to - // generate the random avatars. - urlPrefix - = typeof interfaceConfig === 'object' - && interfaceConfig.RANDOM_AVATAR_URL_PREFIX; - if (urlPrefix) { - urlSuffix = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX; - } else { - // Otherwise, use a default (meeples, of course). - urlPrefix = 'https://abotars.jitsi.net/meeple/'; - urlSuffix = ''; - } - } - - return urlPrefix + md5.hex(key.trim().toLowerCase()) + urlSuffix; + // eslint-disable-next-line object-property-newline + return _getAvatarURL({ avatarID, email, id }, avatarService); } /** diff --git a/webpack.config.js b/webpack.config.js index 0f05a1c0f..dd19718b7 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -15,8 +15,6 @@ const minimize = process.argv.indexOf('-p') !== -1 || process.argv.indexOf('--optimize-minimize') !== -1; -// eslint-disable-next-line camelcase -const node_modules = `${__dirname}/node_modules/`; const plugins = [ new webpack.LoaderOptionsPlugin({ debug: !minimize, @@ -62,7 +60,9 @@ const config = { // Transpile ES2015 (aka ES6) to ES5. Accept the JSX syntax by React // as well. - exclude: node_modules, // eslint-disable-line camelcase + exclude: [ + new RegExp(`${__dirname}/node_modules/(?!js-utils)`) + ], loader: 'babel-loader', options: { // XXX The require.resolve bellow solves failures to locate the