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';
|
2017-11-21 14:55:50 +00:00
|
|
|
import Icon from 'react-native-vector-icons/FontAwesome';
|
|
|
|
import Avatar from '../Avatar';
|
2017-09-01 19:17:53 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
username: {
|
|
|
|
fontWeight: 'bold'
|
|
|
|
},
|
|
|
|
usernameView: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center',
|
|
|
|
marginBottom: 2
|
|
|
|
},
|
|
|
|
alias: {
|
|
|
|
fontSize: 10,
|
|
|
|
color: '#888',
|
|
|
|
paddingLeft: 5
|
|
|
|
},
|
|
|
|
time: {
|
|
|
|
fontSize: 10,
|
|
|
|
color: '#888',
|
|
|
|
paddingLeft: 5
|
2017-11-21 14:55:50 +00:00
|
|
|
},
|
|
|
|
edited: {
|
|
|
|
marginLeft: 5,
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center'
|
2017-09-01 19:17:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-11-24 20:44:52 +00:00
|
|
|
export default class User extends React.PureComponent {
|
2017-09-01 19:17:53 +00:00
|
|
|
static propTypes = {
|
|
|
|
item: PropTypes.object.isRequired,
|
|
|
|
Message_TimeFormat: PropTypes.string.isRequired,
|
2017-11-21 14:55:50 +00:00
|
|
|
onPress: PropTypes.func,
|
|
|
|
baseUrl: PropTypes.string
|
|
|
|
}
|
|
|
|
|
|
|
|
renderEdited(item) {
|
|
|
|
if (!item.editedBy) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<View style={styles.edited}>
|
|
|
|
<Icon name='pencil-square-o' color='#888' size={10} />
|
|
|
|
<Avatar
|
|
|
|
style={{ marginLeft: 5 }}
|
|
|
|
text={item.editedBy.username}
|
|
|
|
size={20}
|
|
|
|
baseUrl={this.props.baseUrl}
|
|
|
|
avatar={item.avatar}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
2017-09-01 19:17:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { item } = this.props;
|
|
|
|
|
|
|
|
const extraStyle = {};
|
|
|
|
if (item.temp) {
|
|
|
|
extraStyle.opacity = 0.3;
|
|
|
|
}
|
|
|
|
|
|
|
|
const username = item.alias || item.u.username;
|
|
|
|
const aliasUsername = item.alias ? (<Text style={styles.alias}>@{item.u.username}</Text>) : null;
|
|
|
|
const time = moment(item.ts).format(this.props.Message_TimeFormat);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={styles.usernameView}>
|
|
|
|
<Text onPress={this.props.onPress} style={styles.username}>
|
|
|
|
{username}
|
|
|
|
</Text>
|
2017-11-21 14:55:50 +00:00
|
|
|
{aliasUsername}
|
|
|
|
<Text style={styles.time}>{time}</Text>
|
|
|
|
{this.renderEdited(item)}
|
2017-09-01 19:17:53 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|