2018-07-20 19:54:46 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { View, Text, StyleSheet } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import moment from 'moment';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2019-08-27 12:25:38 +00:00
|
|
|
import Markdown from '../markdown';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
2019-03-29 19:36:07 +00:00
|
|
|
import sharedStyles from '../../views/Styles';
|
|
|
|
import {
|
|
|
|
COLOR_PRIMARY, COLOR_BACKGROUND_CONTAINER, COLOR_TEXT_DESCRIPTION, COLOR_WHITE
|
|
|
|
} from '../../constants/colors';
|
2018-07-20 19:54:46 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
2018-09-11 16:32:52 +00:00
|
|
|
flexDirection: 'row',
|
|
|
|
marginTop: 10,
|
2019-03-29 19:36:07 +00:00
|
|
|
backgroundColor: COLOR_WHITE
|
2018-07-20 19:54:46 +00:00
|
|
|
},
|
|
|
|
messageContainer: {
|
|
|
|
flex: 1,
|
2018-09-11 16:32:52 +00:00
|
|
|
marginHorizontal: 10,
|
2019-03-29 19:36:07 +00:00
|
|
|
backgroundColor: COLOR_BACKGROUND_CONTAINER,
|
2018-07-20 19:54:46 +00:00
|
|
|
paddingHorizontal: 15,
|
|
|
|
paddingVertical: 10,
|
2018-09-11 16:32:52 +00:00
|
|
|
borderRadius: 4
|
2018-07-20 19:54:46 +00:00
|
|
|
},
|
|
|
|
header: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
username: {
|
2019-03-29 19:36:07 +00:00
|
|
|
color: COLOR_PRIMARY,
|
2018-07-20 19:54:46 +00:00
|
|
|
fontSize: 16,
|
2019-03-29 19:36:07 +00:00
|
|
|
...sharedStyles.textMedium
|
2018-07-20 19:54:46 +00:00
|
|
|
},
|
|
|
|
time: {
|
|
|
|
fontSize: 12,
|
|
|
|
lineHeight: 16,
|
2019-03-29 19:36:07 +00:00
|
|
|
marginLeft: 6,
|
|
|
|
...sharedStyles.textColorDescription,
|
|
|
|
...sharedStyles.textRegular,
|
|
|
|
fontWeight: '300'
|
2018-07-20 19:54:46 +00:00
|
|
|
},
|
|
|
|
close: {
|
2018-09-11 16:32:52 +00:00
|
|
|
marginRight: 10
|
2018-07-20 19:54:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class ReplyPreview extends Component {
|
2018-07-20 19:54:46 +00:00
|
|
|
static propTypes = {
|
2019-08-27 12:25:38 +00:00
|
|
|
useMarkdown: PropTypes.bool,
|
2018-07-20 19:54:46 +00:00
|
|
|
message: PropTypes.object.isRequired,
|
|
|
|
Message_TimeFormat: PropTypes.string.isRequired,
|
2018-09-11 16:32:52 +00:00
|
|
|
close: PropTypes.func.isRequired,
|
|
|
|
baseUrl: PropTypes.string.isRequired,
|
2019-09-16 20:26:32 +00:00
|
|
|
username: PropTypes.string.isRequired,
|
|
|
|
getCustomEmoji: PropTypes.func
|
2018-07-20 19:54:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
shouldComponentUpdate() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-20 19:54:46 +00:00
|
|
|
close = () => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { close } = this.props;
|
|
|
|
close();
|
2018-07-20 19:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-09-11 16:32:52 +00:00
|
|
|
const {
|
2019-09-16 20:26:32 +00:00
|
|
|
message, Message_TimeFormat, baseUrl, username, useMarkdown, getCustomEmoji
|
2018-09-11 16:32:52 +00:00
|
|
|
} = this.props;
|
2018-07-20 19:54:46 +00:00
|
|
|
const time = moment(message.ts).format(Message_TimeFormat);
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={styles.messageContainer}>
|
|
|
|
<View style={styles.header}>
|
|
|
|
<Text style={styles.username}>{message.u.username}</Text>
|
|
|
|
<Text style={styles.time}>{time}</Text>
|
|
|
|
</View>
|
2019-10-02 12:41:51 +00:00
|
|
|
<Markdown msg={message.msg} baseUrl={baseUrl} username={username} getCustomEmoji={getCustomEmoji} numberOfLines={1} useMarkdown={useMarkdown} preview />
|
2018-07-20 19:54:46 +00:00
|
|
|
</View>
|
2019-03-29 19:36:07 +00:00
|
|
|
<CustomIcon name='cross' color={COLOR_TEXT_DESCRIPTION} size={20} style={styles.close} onPress={this.close} />
|
2018-07-20 19:54:46 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2019-08-27 12:25:38 +00:00
|
|
|
useMarkdown: state.markdown.useMarkdown,
|
2019-08-07 13:51:34 +00:00
|
|
|
Message_TimeFormat: state.settings.Message_TimeFormat,
|
|
|
|
baseUrl: state.settings.Site_Url || state.server ? state.server.server : ''
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(ReplyPreview);
|