Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion app/utils/lib/getRoomAvatarURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 6 additions & 1 deletion client/components/basic/avatar/UserAvatar.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import React from 'react';

import BaseAvatar from './BaseAvatar';
import { settings } from '../../../../app/settings';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're supposed to use the SettingsContext (e.g. useSetting)


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 }` : '' }`;

let externalSource = (settings.get('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, '');
externalSource = externalSource !== '' && externalSource.replace('{username}', username);

const avatarUrl = externalSource || url || `/avatar/${ username }${ etag ? `?etag=${ etag }` : '' }`;
return <BaseAvatar url={avatarUrl} title={username} {...props}/>;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down