2019-05-20 20:43:50 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-08-22 18:08:07 +00:00
|
|
|
import { TouchableOpacity } from 'react-native';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
import Avatar from '../Avatar';
|
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
const MessageAvatar = React.memo(({
|
2019-08-22 18:08:07 +00:00
|
|
|
isHeader, avatar, author, baseUrl, user, small, navToRoomInfo
|
2019-05-20 20:43:50 +00:00
|
|
|
}) => {
|
|
|
|
if (isHeader) {
|
2019-08-22 18:08:07 +00:00
|
|
|
const navParam = {
|
|
|
|
t: 'd',
|
|
|
|
rid: author._id
|
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
2019-08-22 18:08:07 +00:00
|
|
|
<TouchableOpacity
|
|
|
|
onPress={() => navToRoomInfo(navParam)}
|
|
|
|
disabled={author._id === user.id}
|
|
|
|
>
|
|
|
|
<Avatar
|
|
|
|
style={small ? styles.avatarSmall : styles.avatar}
|
|
|
|
text={avatar ? '' : author.username}
|
|
|
|
size={small ? 20 : 36}
|
|
|
|
borderRadius={small ? 2 : 4}
|
|
|
|
avatar={avatar}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
userId={user.id}
|
|
|
|
token={user.token}
|
|
|
|
/>
|
|
|
|
</TouchableOpacity>
|
2019-05-20 20:43:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
2019-05-21 13:32:06 +00:00
|
|
|
}, (prevProps, nextProps) => prevProps.isHeader === nextProps.isHeader);
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
MessageAvatar.propTypes = {
|
|
|
|
isHeader: PropTypes.bool,
|
|
|
|
avatar: PropTypes.string,
|
|
|
|
author: PropTypes.obj,
|
|
|
|
baseUrl: PropTypes.string,
|
|
|
|
user: 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;
|