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';
|
|
|
|
|
|
|
|
const Content = React.memo((props) => {
|
|
|
|
if (props.isInfo) {
|
|
|
|
return <Text style={styles.textInfo}>{getInfoMessage({ ...props })}</Text>;
|
|
|
|
}
|
|
|
|
|
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-07-17 14:06:39 +00:00
|
|
|
content = <Text style={styles.text}>{I18n.t('Sent_an_attachment')}</Text>;
|
|
|
|
} 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}
|
|
|
|
numberOfLines={props.tmid ? 1 : 0}
|
2019-08-27 12:25:38 +00:00
|
|
|
channels={props.channels}
|
|
|
|
mentions={props.mentions}
|
2019-07-17 14:06:39 +00:00
|
|
|
useMarkdown={props.useMarkdown}
|
2019-08-22 18:08:07 +00:00
|
|
|
navToRoomInfo={props.navToRoomInfo}
|
2019-08-27 12:25:38 +00:00
|
|
|
tmid={props.tmid}
|
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-07-17 14:06:39 +00:00
|
|
|
}, (prevProps, nextProps) => prevProps.isTemp === nextProps.isTemp && prevProps.msg === nextProps.msg);
|
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,
|
|
|
|
msg: 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;
|