2020-04-30 20:05:59 +00:00
|
|
|
import React, { useContext } from 'react';
|
2019-05-20 20:43:50 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2020-11-04 16:53:44 +00:00
|
|
|
import Avatar from '../Avatar';
|
2019-05-20 20:43:50 +00:00
|
|
|
import styles from './styles';
|
2020-04-30 20:05:59 +00:00
|
|
|
import MessageContext from './Context';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
const MessageAvatar = React.memo(({
|
2020-05-08 17:16:22 +00:00
|
|
|
isHeader, avatar, author, small, navToRoomInfo, emoji, getCustomEmoji, theme
|
2019-05-20 20:43:50 +00:00
|
|
|
}) => {
|
2020-11-04 16:53:44 +00:00
|
|
|
const { user } = useContext(MessageContext);
|
2020-02-17 16:06:46 +00:00
|
|
|
if (isHeader && author) {
|
2019-08-22 18:08:07 +00:00
|
|
|
const navParam = {
|
|
|
|
t: 'd',
|
|
|
|
rid: author._id
|
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
2020-04-30 20:05:59 +00:00
|
|
|
<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)}
|
2020-05-08 17:16:22 +00:00
|
|
|
getCustomEmoji={getCustomEmoji}
|
2020-04-30 20:05:59 +00:00
|
|
|
avatar={avatar}
|
2020-05-08 17:16:22 +00:00
|
|
|
emoji={emoji}
|
|
|
|
theme={theme}
|
2020-04-30 20:05:59 +00:00
|
|
|
/>
|
2019-05-20 20:43:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
2019-09-16 20:26:32 +00:00
|
|
|
});
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
MessageAvatar.propTypes = {
|
|
|
|
isHeader: PropTypes.bool,
|
|
|
|
avatar: PropTypes.string,
|
2020-05-08 17:16:22 +00:00
|
|
|
emoji: PropTypes.string,
|
2019-05-20 20:43:50 +00:00
|
|
|
author: PropTypes.obj,
|
2019-08-22 18:08:07 +00:00
|
|
|
small: PropTypes.bool,
|
2020-05-08 17:16:22 +00:00
|
|
|
navToRoomInfo: PropTypes.func,
|
|
|
|
getCustomEmoji: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
MessageAvatar.displayName = 'MessageAvatar';
|
|
|
|
|
|
|
|
export default MessageAvatar;
|