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';
|
|
|
|
|
|
|
|
import Avatar from '../Avatar';
|
|
|
|
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-04-30 20:05:59 +00:00
|
|
|
isHeader, avatar, author, small, navToRoomInfo
|
2019-05-20 20:43:50 +00:00
|
|
|
}) => {
|
2020-04-30 20:05:59 +00:00
|
|
|
const { baseUrl, 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)}
|
|
|
|
avatar={avatar}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
userId={user.id}
|
|
|
|
token={user.token}
|
|
|
|
/>
|
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,
|
|
|
|
author: PropTypes.obj,
|
2019-08-22 18:08:07 +00:00
|
|
|
small: PropTypes.bool,
|
|
|
|
navToRoomInfo: PropTypes.func
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
MessageAvatar.displayName = 'MessageAvatar';
|
|
|
|
|
|
|
|
export default MessageAvatar;
|