2021-09-13 20:41:05 +00:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
|
|
|
|
import Avatar from '../Avatar';
|
|
|
|
import styles from './styles';
|
|
|
|
import MessageContext from './Context';
|
|
|
|
import { IMessageAvatar } from './interfaces';
|
2022-03-29 16:23:45 +00:00
|
|
|
import { SubscriptionType } from '../../definitions';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-03-29 16:23:45 +00:00
|
|
|
const MessageAvatar = React.memo(({ isHeader, avatar, author, small, navToRoomInfo, emoji, getCustomEmoji }: IMessageAvatar) => {
|
|
|
|
const { user } = useContext(MessageContext);
|
|
|
|
if (isHeader && author) {
|
|
|
|
const navParam = {
|
|
|
|
t: SubscriptionType.DIRECT,
|
|
|
|
rid: author._id
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<Avatar
|
|
|
|
style={small ? styles.avatarSmall : styles.avatar}
|
|
|
|
text={avatar ? '' : author.username}
|
|
|
|
size={small ? 20 : 36}
|
|
|
|
borderRadius={small ? 2 : 4}
|
|
|
|
onPress={author._id === user.id ? undefined : () => navToRoomInfo(navParam)}
|
2022-12-12 17:47:12 +00:00
|
|
|
isUserProfile={author._id === user.id}
|
2022-03-29 16:23:45 +00:00
|
|
|
getCustomEmoji={getCustomEmoji}
|
|
|
|
avatar={avatar}
|
|
|
|
emoji={emoji}
|
|
|
|
/>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
2022-03-29 16:23:45 +00:00
|
|
|
return null;
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
MessageAvatar.displayName = 'MessageAvatar';
|
|
|
|
|
|
|
|
export default MessageAvatar;
|