Rocket.Chat.ReactNative/app/containers/Message.js

70 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-08-09 01:40:55 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import { View, StyleSheet } from 'react-native';
2017-08-10 14:27:28 +00:00
import { emojify } from 'react-emojione';
import Markdown from 'react-native-easy-markdown';
2017-09-01 20:00:31 +00:00
import Card from './message/Card';
import Avatar from './message/Avatar';
import User from './message/User';
2017-08-09 01:40:55 +00:00
const styles = StyleSheet.create({
content: {
flexGrow: 1
},
2017-08-09 01:40:55 +00:00
message: {
2017-08-10 15:16:47 +00:00
padding: 12,
paddingTop: 6,
paddingBottom: 6,
2017-08-09 01:40:55 +00:00
flexDirection: 'row',
transform: [{ scaleY: -1 }]
}
});
export default class Message extends React.PureComponent {
static propTypes = {
item: PropTypes.object.isRequired,
baseUrl: PropTypes.string.isRequired,
Message_TimeFormat: PropTypes.string.isRequired
2017-08-09 01:40:55 +00:00
}
attachments() {
return this.props.item.attachments.length ? <Card data={this.props.item.attachments[0]} /> : null;
}
2017-08-09 01:40:55 +00:00
render() {
const { item } = this.props;
2017-08-09 01:40:55 +00:00
const extraStyle = {};
if (item.temp) {
2017-08-09 01:40:55 +00:00
extraStyle.opacity = 0.3;
}
const msg = emojify(item.msg, { output: 'unicode' });
const username = item.alias || item.u.username;
2017-08-10 14:27:28 +00:00
2017-08-09 01:40:55 +00:00
return (
<View style={[styles.message, extraStyle]}>
2017-09-01 20:00:31 +00:00
<Avatar
style={{ marginRight: 10 }}
text={item.avatar ? '' : username}
size={40}
baseUrl={this.props.baseUrl}
avatar={item.avatar}
/>
<View style={[styles.content]}>
<User
onPress={this._onPress}
item={item}
Message_TimeFormat={this.props.Message_TimeFormat}
/>
{this.attachments()}
2017-08-10 14:27:28 +00:00
<Markdown>
{msg}
</Markdown>
2017-08-09 01:40:55 +00:00
</View>
</View>
);
}
}