2017-09-01 19:17:53 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { View, Text, StyleSheet } from 'react-native';
|
|
|
|
import moment from 'moment';
|
|
|
|
|
2019-07-29 20:44:39 +00:00
|
|
|
import MessageError from './MessageError';
|
2019-03-29 19:36:07 +00:00
|
|
|
import sharedStyles from '../../views/Styles';
|
2019-04-08 12:35:28 +00:00
|
|
|
import messageStyles from './styles';
|
2019-03-29 19:36:07 +00:00
|
|
|
|
2017-09-01 19:17:53 +00:00
|
|
|
const styles = StyleSheet.create({
|
2019-03-01 16:49:11 +00:00
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
2019-03-29 19:36:07 +00:00
|
|
|
alignItems: 'center'
|
2019-03-01 16:49:11 +00:00
|
|
|
},
|
2017-09-01 19:17:53 +00:00
|
|
|
username: {
|
2018-09-11 16:32:52 +00:00
|
|
|
fontSize: 16,
|
2019-03-29 19:36:07 +00:00
|
|
|
lineHeight: 22,
|
|
|
|
...sharedStyles.textColorNormal,
|
|
|
|
...sharedStyles.textMedium
|
2017-09-01 19:17:53 +00:00
|
|
|
},
|
2019-03-01 16:49:11 +00:00
|
|
|
titleContainer: {
|
|
|
|
flex: 1,
|
2017-09-01 19:17:53 +00:00
|
|
|
flexDirection: 'row',
|
2019-03-01 16:49:11 +00:00
|
|
|
alignItems: 'center'
|
2017-09-01 19:17:53 +00:00
|
|
|
},
|
|
|
|
alias: {
|
2018-09-11 16:32:52 +00:00
|
|
|
fontSize: 14,
|
2019-03-29 19:36:07 +00:00
|
|
|
...sharedStyles.textColorDescription,
|
|
|
|
...sharedStyles.textRegular
|
2017-09-01 19:17:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
const User = React.memo(({
|
2019-07-29 20:44:39 +00:00
|
|
|
isHeader, useRealName, author, alias, ts, timeFormat, hasError, ...props
|
2019-05-20 20:43:50 +00:00
|
|
|
}) => {
|
2019-07-29 20:44:39 +00:00
|
|
|
if (isHeader || hasError) {
|
2019-05-20 20:43:50 +00:00
|
|
|
const username = (useRealName && author.name) || author.username;
|
2019-03-29 19:36:07 +00:00
|
|
|
const aliasUsername = alias ? (<Text style={styles.alias}> @{username}</Text>) : null;
|
2018-09-25 19:28:42 +00:00
|
|
|
const time = moment(ts).format(timeFormat);
|
2017-09-01 19:17:53 +00:00
|
|
|
|
|
|
|
return (
|
2019-03-01 16:49:11 +00:00
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={styles.titleContainer}>
|
2019-03-29 19:36:07 +00:00
|
|
|
<Text style={styles.username} numberOfLines={1}>
|
2019-03-01 16:49:11 +00:00
|
|
|
{alias || username}
|
2019-03-29 19:36:07 +00:00
|
|
|
{aliasUsername}
|
2019-03-01 16:49:11 +00:00
|
|
|
</Text>
|
|
|
|
</View>
|
2019-04-08 12:35:28 +00:00
|
|
|
<Text style={messageStyles.time}>{time}</Text>
|
2019-07-29 20:44:39 +00:00
|
|
|
{ hasError && <MessageError hasError={hasError} {...props} /> }
|
2017-09-01 19:17:53 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2019-05-20 20:43:50 +00:00
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
User.propTypes = {
|
|
|
|
isHeader: PropTypes.bool,
|
2019-07-29 20:44:39 +00:00
|
|
|
hasError: PropTypes.bool,
|
2019-05-20 20:43:50 +00:00
|
|
|
useRealName: PropTypes.bool,
|
|
|
|
author: PropTypes.object,
|
|
|
|
alias: PropTypes.string,
|
|
|
|
ts: PropTypes.instanceOf(Date),
|
|
|
|
timeFormat: PropTypes.string
|
|
|
|
};
|
|
|
|
User.displayName = 'MessageUser';
|
|
|
|
|
|
|
|
export default User;
|