2017-08-09 01:40:55 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-09-01 19:17:53 +00:00
|
|
|
import { View, StyleSheet } from 'react-native';
|
2017-08-10 14:27:28 +00:00
|
|
|
import { emojify } from 'react-emojione';
|
2017-08-10 16:25:50 +00:00
|
|
|
import Markdown from 'react-native-easy-markdown';
|
2017-08-14 00:03:33 +00:00
|
|
|
|
2017-08-15 19:28:46 +00:00
|
|
|
import Card from './message/card';
|
2017-09-01 19:17:53 +00:00
|
|
|
import Avatar from './message/Avatar';
|
|
|
|
import User from './message/User';
|
2017-08-09 01:40:55 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2017-08-15 19:28:46 +00:00
|
|
|
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,
|
2017-08-14 00:03:33 +00:00
|
|
|
baseUrl: PropTypes.string.isRequired,
|
|
|
|
Message_TimeFormat: PropTypes.string.isRequired
|
2017-08-09 01:40:55 +00:00
|
|
|
}
|
2017-09-01 19:17:53 +00:00
|
|
|
|
2017-08-15 19:28:46 +00:00
|
|
|
attachments() {
|
|
|
|
return this.props.item.attachments.length ? <Card data={this.props.item.attachments[0]} /> : null;
|
|
|
|
}
|
2017-09-01 19:17:53 +00:00
|
|
|
|
2017-08-09 01:40:55 +00:00
|
|
|
render() {
|
2017-08-14 00:03:33 +00:00
|
|
|
const { item } = this.props;
|
|
|
|
|
2017-08-09 01:40:55 +00:00
|
|
|
const extraStyle = {};
|
2017-08-14 00:03:33 +00:00
|
|
|
if (item.temp) {
|
2017-08-09 01:40:55 +00:00
|
|
|
extraStyle.opacity = 0.3;
|
|
|
|
}
|
|
|
|
|
2017-08-14 00:03:33 +00:00
|
|
|
const msg = emojify(item.msg, { output: 'unicode' });
|
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 19:17:53 +00:00
|
|
|
<Avatar item={item} baseUrl={this.props.baseUrl} />
|
2017-08-15 19:28:46 +00:00
|
|
|
<View style={[styles.content]}>
|
2017-09-01 19:17:53 +00:00
|
|
|
<User
|
|
|
|
onPress={this._onPress}
|
|
|
|
item={item}
|
|
|
|
Message_TimeFormat={this.props.Message_TimeFormat}
|
|
|
|
/>
|
2017-08-15 19:28:46 +00:00
|
|
|
{this.attachments()}
|
2017-08-10 14:27:28 +00:00
|
|
|
<Markdown>
|
|
|
|
{msg}
|
|
|
|
</Markdown>
|
2017-08-09 01:40:55 +00:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|