[IMPROVE] Accept user avatar url from external provider (#4002)
* [IMPROVE] Accept url to user avatar from external provider * fix avatar sidebar
This commit is contained in:
parent
3c53d48a3e
commit
21c8de56ea
|
@ -28,7 +28,8 @@ const Avatar = React.memo(
|
||||||
text,
|
text,
|
||||||
size = 25,
|
size = 25,
|
||||||
borderRadius = 4,
|
borderRadius = 4,
|
||||||
type = SubscriptionType.DIRECT
|
type = SubscriptionType.DIRECT,
|
||||||
|
externalProviderUrl
|
||||||
}: IAvatar) => {
|
}: IAvatar) => {
|
||||||
const { theme } = useTheme();
|
const { theme } = useTheme();
|
||||||
|
|
||||||
|
@ -67,7 +68,8 @@ const Avatar = React.memo(
|
||||||
avatarETag,
|
avatarETag,
|
||||||
serverVersion,
|
serverVersion,
|
||||||
rid,
|
rid,
|
||||||
blockUnauthenticatedAccess
|
blockUnauthenticatedAccess,
|
||||||
|
externalProviderUrl
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,10 @@ class AvatarContainer extends React.Component<IAvatar, any> {
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps: IAvatar, nextState: { avatarETag: string }) {
|
shouldComponentUpdate(nextProps: IAvatar, nextState: { avatarETag: string }) {
|
||||||
const { avatarETag } = this.state;
|
const { avatarETag } = this.state;
|
||||||
const { text, type } = this.props;
|
const { text, type, externalProviderUrl } = this.props;
|
||||||
|
if (nextProps.externalProviderUrl !== externalProviderUrl) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (nextState.avatarETag !== avatarETag) {
|
if (nextState.avatarETag !== avatarETag) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -100,6 +103,7 @@ const mapStateToProps = (state: IApplicationState) => ({
|
||||||
blockUnauthenticatedAccess:
|
blockUnauthenticatedAccess:
|
||||||
(state.share.settings?.Accounts_AvatarBlockUnauthenticatedAccess as boolean) ??
|
(state.share.settings?.Accounts_AvatarBlockUnauthenticatedAccess as boolean) ??
|
||||||
state.settings.Accounts_AvatarBlockUnauthenticatedAccess ??
|
state.settings.Accounts_AvatarBlockUnauthenticatedAccess ??
|
||||||
true
|
true,
|
||||||
|
externalProviderUrl: state.settings.Accounts_AvatarExternalProviderUrl as string
|
||||||
});
|
});
|
||||||
export default connect(mapStateToProps)(AvatarContainer);
|
export default connect(mapStateToProps)(AvatarContainer);
|
||||||
|
|
|
@ -23,4 +23,5 @@ export interface IAvatar {
|
||||||
rid?: string;
|
rid?: string;
|
||||||
blockUnauthenticatedAccess?: boolean;
|
blockUnauthenticatedAccess?: boolean;
|
||||||
serverVersion: string | null;
|
serverVersion: string | null;
|
||||||
|
externalProviderUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,5 +205,8 @@ export const defaultSettings = {
|
||||||
},
|
},
|
||||||
Canned_Responses_Enable: {
|
Canned_Responses_Enable: {
|
||||||
type: 'valueAsBoolean'
|
type: 'valueAsBoolean'
|
||||||
|
},
|
||||||
|
Accounts_AvatarExternalProviderUrl: {
|
||||||
|
type: 'valueAsString'
|
||||||
}
|
}
|
||||||
} as const;
|
} as const;
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { SubscriptionType } from '../definitions/ISubscription';
|
||||||
import { IAvatar } from '../containers/Avatar/interfaces';
|
import { IAvatar } from '../containers/Avatar/interfaces';
|
||||||
import { compareServerVersion } from '../lib/methods/helpers/compareServerVersion';
|
import { compareServerVersion } from '../lib/methods/helpers/compareServerVersion';
|
||||||
|
|
||||||
const formatUrl = (url: string, size: number, query: string) => `${url}?format=png&size=${size}${query}`;
|
const formatUrl = (url: string, size: number, query?: string) => `${url}?format=png&size=${size}${query}`;
|
||||||
|
|
||||||
export const avatarURL = ({
|
export const avatarURL = ({
|
||||||
type,
|
type,
|
||||||
|
@ -14,11 +14,16 @@ export const avatarURL = ({
|
||||||
avatarETag,
|
avatarETag,
|
||||||
rid,
|
rid,
|
||||||
blockUnauthenticatedAccess,
|
blockUnauthenticatedAccess,
|
||||||
serverVersion
|
serverVersion,
|
||||||
|
externalProviderUrl
|
||||||
}: IAvatar): string => {
|
}: IAvatar): string => {
|
||||||
let room;
|
let room;
|
||||||
if (type === SubscriptionType.DIRECT) {
|
if (type === SubscriptionType.DIRECT) {
|
||||||
room = text;
|
room = text;
|
||||||
|
if (externalProviderUrl) {
|
||||||
|
const externalUri = externalProviderUrl.trim().replace(/\/+$/, '').replace('{username}', room);
|
||||||
|
return formatUrl(`${externalUri}`, size);
|
||||||
|
}
|
||||||
} else if (rid && !compareServerVersion(serverVersion, 'lowerThan', '3.6.0')) {
|
} else if (rid && !compareServerVersion(serverVersion, 'lowerThan', '3.6.0')) {
|
||||||
room = `room/${rid}`;
|
room = `room/${rid}`;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue