2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { View } from 'react-native';
|
2022-05-31 16:08:18 +00:00
|
|
|
import FastImage from 'react-native-fast-image';
|
2021-09-13 20:41:05 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
|
|
|
import { settings as RocketChatSettings } from '@rocket.chat/sdk';
|
|
|
|
|
2022-06-06 14:17:51 +00:00
|
|
|
import { getAvatarURL } from '../../lib/methods/helpers/getAvatarUrl';
|
|
|
|
import { SubscriptionType } from '../../definitions';
|
2021-09-13 20:41:05 +00:00
|
|
|
import Emoji from '../markdown/Emoji';
|
|
|
|
import { IAvatar } from './interfaces';
|
|
|
|
|
|
|
|
const Avatar = React.memo(
|
|
|
|
({
|
|
|
|
server,
|
|
|
|
style,
|
|
|
|
avatar,
|
|
|
|
children,
|
2022-06-06 15:33:36 +00:00
|
|
|
userId,
|
|
|
|
token,
|
2021-09-13 20:41:05 +00:00
|
|
|
onPress,
|
|
|
|
emoji,
|
|
|
|
getCustomEmoji,
|
|
|
|
avatarETag,
|
|
|
|
isStatic,
|
|
|
|
rid,
|
|
|
|
blockUnauthenticatedAccess,
|
|
|
|
serverVersion,
|
|
|
|
text,
|
|
|
|
size = 25,
|
|
|
|
borderRadius = 4,
|
2022-04-19 00:52:02 +00:00
|
|
|
type = SubscriptionType.DIRECT,
|
|
|
|
externalProviderUrl
|
2022-01-12 12:54:04 +00:00
|
|
|
}: IAvatar) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
if ((!text && !avatar && !emoji && !rid) || !server) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const avatarStyle = {
|
|
|
|
width: size,
|
|
|
|
height: size,
|
|
|
|
borderRadius
|
|
|
|
};
|
|
|
|
|
|
|
|
let image;
|
|
|
|
if (emoji) {
|
|
|
|
image = (
|
2022-07-04 18:10:14 +00:00
|
|
|
<Emoji baseUrl={server} getCustomEmoji={getCustomEmoji} isMessageContainsOnlyEmoji literal={emoji} style={avatarStyle} />
|
2021-09-13 20:41:05 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
let uri = avatar;
|
|
|
|
if (!isStatic) {
|
2022-06-06 14:17:51 +00:00
|
|
|
uri = getAvatarURL({
|
2021-09-13 20:41:05 +00:00
|
|
|
type,
|
|
|
|
text,
|
|
|
|
size,
|
2022-06-06 15:33:36 +00:00
|
|
|
userId,
|
|
|
|
token,
|
2021-09-13 20:41:05 +00:00
|
|
|
avatar,
|
|
|
|
server,
|
|
|
|
avatarETag,
|
|
|
|
serverVersion,
|
|
|
|
rid,
|
2022-04-19 00:52:02 +00:00
|
|
|
blockUnauthenticatedAccess,
|
|
|
|
externalProviderUrl
|
2021-09-13 20:41:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
image = (
|
|
|
|
<FastImage
|
|
|
|
style={avatarStyle}
|
|
|
|
source={{
|
|
|
|
uri,
|
|
|
|
headers: RocketChatSettings.customHeaders,
|
|
|
|
priority: FastImage.priority.high
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onPress) {
|
|
|
|
image = <Touchable onPress={onPress}>{image}</Touchable>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-10-06 20:30:10 +00:00
|
|
|
<View style={[avatarStyle, style]} testID='avatar'>
|
2021-09-13 20:41:05 +00:00
|
|
|
{image}
|
|
|
|
{children}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
export default Avatar;
|