[FIX] Wrong avatar urls when using providers (#18929)

pull/19263/head
Martin Schoeler 5 years ago committed by GitHub
parent b5cd60f65e
commit 0b488a37d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/lib/server/startup/settings.js
  2. 2
      app/utils/lib/getRoomAvatarURL.js
  3. 8
      client/components/basic/avatar/UserAvatar.js
  4. 2
      packages/rocketchat-i18n/i18n/en.i18n.json

@ -522,6 +522,11 @@ settings.addGroup('Accounts', function() {
public: true,
});
this.add('Accounts_RoomAvatarExternalProviderUrl', '', {
type: 'string',
public: true,
});
this.add('Accounts_AvatarCacheTime', 3600, {
type: 'int',
i18nDescription: 'Accounts_AvatarCacheTime_description',

@ -2,7 +2,7 @@ import { getAvatarURL } from './getAvatarURL';
import { settings } from '../../settings';
export const getRoomAvatarURL = function(roomId, etag) {
const externalSource = (settings.get('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, '');
const externalSource = (settings.get('Accounts_RoomAvatarExternalProviderUrl') || '').trim().replace(/\/$/, '');
if (externalSource !== '') {
return externalSource.replace('{roomId}', roomId);
}

@ -1,13 +1,19 @@
import React from 'react';
import BaseAvatar from './BaseAvatar';
import { useSetting } from '../../../contexts/SettingsContext';
function UserAvatar({ url, username, etag, ...props }) {
// NOW, `username` and `etag` props are enough to determine the whole state of
// this component, but it must be as performatic as possible as it will be
// rendered many times; and some of the state can be derived at the ancestors.
// Ideally, it should be a purely visual component.
const avatarUrl = url || `/avatar/${ username }${ etag ? `?etag=${ etag }` : '' }`;
const externalProviderUrl = useSetting('Accounts_AvatarExternalProviderUrl');
let externalSource = (externalProviderUrl || '').trim().replace(/\/$/, '');
externalSource = externalSource !== '' && externalSource.replace('{username}', username);
const avatarUrl = externalSource || url || `/avatar/${ username }${ etag ? `?etag=${ etag }` : '' }`;
return <BaseAvatar url={avatarUrl} title={username} {...props}/>;
}

@ -54,6 +54,8 @@
"Accounts_AvatarSize": "Avatar Size",
"Accounts_AvatarExternalProviderUrl": "Avatar External Provider URL",
"Accounts_AvatarExternalProviderUrl_Description": "Example: `https://acme.com/api/v1/{username}`",
"Accounts_RoomAvatarExternalProviderUrl": "Room Avatar External Provider URL",
"Accounts_RoomAvatarExternalProviderUrl_Description": "Example: `https://acme.com/api/v1/{roomId}`",
"Accounts_BlockedDomainsList": "Blocked Domains List",
"Accounts_BlockedDomainsList_Description": "Comma-separated list of blocked domains",
"Accounts_Verify_Email_For_External_Accounts": "Verify Email for External Accounts",

Loading…
Cancel
Save