Refactor avatar

Don't use abotars, as they are no longer used in Jitsi Meet.
This commit is contained in:
Saúl Ibarra Corretgé 2020-05-19 09:48:06 +02:00
parent 9b84fe5999
commit a1a52c4b42
4 changed files with 27 additions and 11 deletions

View File

@ -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.
*

View File

@ -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;

View File

@ -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,

View File

@ -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",