diff options
author | Saúl Ibarra Corretgé <s@saghul.net> | 2020-05-19 09:48:06 +0200 |
---|---|---|
committer | Saúl Ibarra Corretgé <s@saghul.net> | 2020-05-20 12:06:27 +0200 |
commit | a1a52c4b4261096e0d0e65a62053de61b963f47d (patch) | |
tree | 1f661eecf7bc69870ed40594d9e74d2a00754152 | |
parent | 9b84fe5999af0e5c620c1f25fb727bb26efef6e1 (diff) |
Refactor avatar
Don't use abotars, as they are no longer used in Jitsi Meet.
-rw-r--r-- | app/features/settings/functions.js | 21 | ||||
-rw-r--r-- | app/features/settings/middleware.js | 11 | ||||
-rw-r--r-- | app/features/settings/reducer.js | 5 | ||||
-rw-r--r-- | package.json | 1 |
4 files changed, 27 insertions, 11 deletions
diff --git a/app/features/settings/functions.js b/app/features/settings/functions.js index b3a7392..60be339 100644 --- a/app/features/settings/functions.js +++ b/app/features/settings/functions.js @@ -1,5 +1,26 @@ // @flow +import md5 from 'js-md5'; + +/** + * Generates an avatar URL for a user, given the name and email settings. + * + * @param {Object} state - The redux state. + * @returns {string} - The generated avatar URL. + */ +export function getAvatarURL(state: Object) { + const { email, name } = state.settings; + const encodedName = encodeURIComponent(name || ''); + + if (email) { + const md5email = md5.hex(email.trim().toLowerCase()); + + return `https://www.gravatar.com/avatar/${md5email}?d=https%3A%2F%2Fui-avatars.com%2Fapi%2F/${encodedName}/128`; + } + + return `https://ui-avatars.com/api/?name=${encodedName}&size=128`; +} + /** * Get's the value for the given setting, providing a default value. * diff --git a/app/features/settings/middleware.js b/app/features/settings/middleware.js index ece54ea..49f3bc8 100644 --- a/app/features/settings/middleware.js +++ b/app/features/settings/middleware.js @@ -1,8 +1,8 @@ // @flow -import { getAvatarURL } from 'js-utils'; import { SET_EMAIL, SET_NAME } from './actionTypes'; import { setAvatarURL } from './actions'; +import { getAvatarURL } from './functions'; export default (store: Object) => (next: Function) => (action: Object) => { const result = next(action); @@ -10,14 +10,9 @@ export default (store: Object) => (next: Function) => (action: Object) => { switch (action.type) { case SET_EMAIL: - case SET_NAME: { - const avatarURL = getAvatarURL({ - email: state.settings.email, - id: state.settings.name - }); + case SET_NAME: + store.dispatch(setAvatarURL(getAvatarURL(state))); - store.dispatch(setAvatarURL(avatarURL)); - } } return result; diff --git a/app/features/settings/reducer.js b/app/features/settings/reducer.js index bed9a11..ff6df6e 100644 --- a/app/features/settings/reducer.js +++ b/app/features/settings/reducer.js @@ -1,7 +1,5 @@ // @flow -import { getAvatarURL } from 'js-utils'; - import { SET_ALWAYS_ON_TOP_WINDOW_ENABLED, SET_AUDIO_MUTED, @@ -12,6 +10,7 @@ import { SET_SERVER_TIMEOUT, SET_VIDEO_MUTED } from './actionTypes'; +import { getAvatarURL } from './functions'; type State = { avatarURL: string, @@ -28,7 +27,7 @@ const username = window.jitsiNodeAPI.osUserInfo().username; const DEFAULT_STATE = { alwaysOnTopWindowEnabled: true, - avatarURL: getAvatarURL({ id: username }), + avatarURL: getAvatarURL({ settings: { name: username } }), email: '', name: username, serverURL: undefined, diff --git a/package.json b/package.json index e4f47ee..485677a 100644 --- a/package.json +++ b/package.json @@ -143,6 +143,7 @@ "file-loader": "6.0.0", "flow-bin": "0.109.0", "html-webpack-plugin": "4.0.4", + "js-md5": "0.7.3", "patch-package": "6.2.2", "precommit-hook": "3.0.0", "style-loader": "1.1.3", |