2019-05-20 20:43:50 +00:00
|
|
|
import React from 'react';
|
2019-07-17 14:06:39 +00:00
|
|
|
import { Text, View } from 'react-native';
|
2019-05-20 20:43:50 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import styles from './styles';
|
2019-08-27 12:25:38 +00:00
|
|
|
import Markdown from '../markdown';
|
2019-05-20 20:43:50 +00:00
|
|
|
import { getInfoMessage } from './utils';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
const Content = React.memo((props) => {
|
|
|
|
if (props.isInfo) {
|
2019-12-04 16:39:53 +00:00
|
|
|
return <Text style={[styles.textInfo, { color: themes[props.theme].auxiliaryText }]}>{getInfoMessage({ ...props })}</Text>;
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
|
|
|
|
2019-07-17 14:06:39 +00:00
|
|
|
let content = null;
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
if (props.tmid && !props.msg) {
|
2019-12-04 16:39:53 +00:00
|
|
|
content = <Text style={[styles.text, { color: themes[props.theme].titleText }]}>{I18n.t('Sent_an_attachment')}</Text>;
|
2019-07-17 14:06:39 +00:00
|
|
|
} else {
|
|
|
|
content = (
|
|
|
|
<Markdown
|
|
|
|
msg={props.msg}
|
|
|
|
baseUrl={props.baseUrl}
|
2019-08-27 12:25:38 +00:00
|
|
|
getCustomEmoji={props.getCustomEmoji}
|
2019-07-17 14:06:39 +00:00
|
|
|
username={props.user.username}
|
|
|
|
isEdited={props.isEdited}
|
2019-09-16 20:26:32 +00:00
|
|
|
numberOfLines={(props.tmid && !props.isThreadRoom) ? 1 : 0}
|
2019-10-02 12:41:51 +00:00
|
|
|
preview={props.tmid && !props.isThreadRoom}
|
2019-08-27 12:25:38 +00:00
|
|
|
channels={props.channels}
|
|
|
|
mentions={props.mentions}
|
2019-09-16 20:26:32 +00:00
|
|
|
useMarkdown={props.useMarkdown && (!props.tmid || props.isThreadRoom)}
|
2019-08-22 18:08:07 +00:00
|
|
|
navToRoomInfo={props.navToRoomInfo}
|
2019-08-27 12:25:38 +00:00
|
|
|
tmid={props.tmid}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={props.theme}
|
2019-07-17 14:06:39 +00:00
|
|
|
/>
|
|
|
|
);
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-07-17 14:06:39 +00:00
|
|
|
<View style={props.isTemp && styles.temp}>
|
|
|
|
{content}
|
|
|
|
</View>
|
2019-05-20 20:43:50 +00:00
|
|
|
);
|
2019-12-04 16:39:53 +00:00
|
|
|
}, (prevProps, nextProps) => prevProps.isTemp === nextProps.isTemp && prevProps.msg === nextProps.msg && prevProps.theme === nextProps.theme);
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
Content.propTypes = {
|
2019-07-17 14:06:39 +00:00
|
|
|
isTemp: PropTypes.bool,
|
2019-05-20 20:43:50 +00:00
|
|
|
isInfo: PropTypes.bool,
|
|
|
|
tmid: PropTypes.string,
|
2019-09-16 20:26:32 +00:00
|
|
|
isThreadRoom: PropTypes.bool,
|
2019-05-20 20:43:50 +00:00
|
|
|
msg: PropTypes.string,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2019-08-27 12:25:38 +00:00
|
|
|
isEdited: PropTypes.bool,
|
|
|
|
useMarkdown: PropTypes.bool,
|
2019-05-20 20:43:50 +00:00
|
|
|
baseUrl: PropTypes.string,
|
|
|
|
user: PropTypes.object,
|
2019-08-27 12:25:38 +00:00
|
|
|
getCustomEmoji: PropTypes.func,
|
2019-05-20 20:43:50 +00:00
|
|
|
channels: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
2019-08-27 12:25:38 +00:00
|
|
|
mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
|
|
|
navToRoomInfo: PropTypes.func
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
Content.displayName = 'MessageContent';
|
|
|
|
|
|
|
|
export default Content;
|