2020-04-30 20:05:59 +00:00
|
|
|
import React, { useContext } 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';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import styles from './styles';
|
2019-08-27 12:25:38 +00:00
|
|
|
import Markdown from '../markdown';
|
2020-12-01 19:26:03 +00:00
|
|
|
import User from './User';
|
|
|
|
import { getInfoMessage, SYSTEM_MESSAGE_TYPES_WITH_AUTHOR_NAME } from './utils';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2020-04-30 20:05:59 +00:00
|
|
|
import MessageContext from './Context';
|
2020-09-11 14:31:38 +00:00
|
|
|
import Encrypted from './Encrypted';
|
|
|
|
import { E2E_MESSAGE_TYPE } from '../../lib/encryption/constants';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
const Content = React.memo((props) => {
|
|
|
|
if (props.isInfo) {
|
2020-03-03 20:27:38 +00:00
|
|
|
const infoMessage = getInfoMessage({ ...props });
|
2020-12-01 19:26:03 +00:00
|
|
|
|
|
|
|
const renderMessageContent = (
|
2020-03-03 20:27:38 +00:00
|
|
|
<Text
|
|
|
|
style={[styles.textInfo, { color: themes[props.theme].auxiliaryText }]}
|
|
|
|
accessibilityLabel={infoMessage}
|
2020-12-01 19:26:03 +00:00
|
|
|
>
|
|
|
|
{infoMessage}
|
2020-03-03 20:27:38 +00:00
|
|
|
</Text>
|
|
|
|
);
|
2020-12-01 19:26:03 +00:00
|
|
|
|
|
|
|
if (SYSTEM_MESSAGE_TYPES_WITH_AUTHOR_NAME.includes(props.type)) {
|
|
|
|
return (
|
|
|
|
<Text>
|
|
|
|
<User {...props} /> {renderMessageContent}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return renderMessageContent;
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
|
|
|
|
2020-09-11 14:31:38 +00:00
|
|
|
const isPreview = props.tmid && !props.isThreadRoom;
|
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-17 14:08:06 +00:00
|
|
|
content = <Text style={[styles.text, { color: themes[props.theme].bodyText }]}>{I18n.t('Sent_an_attachment')}</Text>;
|
2020-09-11 14:31:38 +00:00
|
|
|
} else if (props.isEncrypted) {
|
|
|
|
content = <Text style={[styles.textInfo, { color: themes[props.theme].auxiliaryText }]}>{I18n.t('Encrypted_message')}</Text>;
|
2019-07-17 14:06:39 +00:00
|
|
|
} else {
|
2021-05-26 17:24:54 +00:00
|
|
|
const { baseUrl, user, onLinkPress } = useContext(MessageContext);
|
2019-07-17 14:06:39 +00:00
|
|
|
content = (
|
|
|
|
<Markdown
|
|
|
|
msg={props.msg}
|
2020-04-30 20:05:59 +00:00
|
|
|
baseUrl={baseUrl}
|
2019-08-27 12:25:38 +00:00
|
|
|
getCustomEmoji={props.getCustomEmoji}
|
2020-04-30 20:05:59 +00:00
|
|
|
username={user.username}
|
2019-07-17 14:06:39 +00:00
|
|
|
isEdited={props.isEdited}
|
2020-09-11 14:31:38 +00:00
|
|
|
numberOfLines={isPreview ? 1 : 0}
|
|
|
|
preview={isPreview}
|
2019-08-27 12:25:38 +00:00
|
|
|
channels={props.channels}
|
|
|
|
mentions={props.mentions}
|
2019-08-22 18:08:07 +00:00
|
|
|
navToRoomInfo={props.navToRoomInfo}
|
2019-08-27 12:25:38 +00:00
|
|
|
tmid={props.tmid}
|
2020-02-21 16:13:05 +00:00
|
|
|
useRealName={props.useRealName}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={props.theme}
|
2021-05-26 17:24:54 +00:00
|
|
|
onLinkPress={onLinkPress}
|
2019-07-17 14:06:39 +00:00
|
|
|
/>
|
|
|
|
);
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
|
|
|
|
2020-09-11 14:31:38 +00:00
|
|
|
// If this is a encrypted message and is not a preview
|
|
|
|
if (props.type === E2E_MESSAGE_TYPE && !isPreview) {
|
|
|
|
content = (
|
|
|
|
<View style={styles.flex}>
|
|
|
|
<View style={styles.contentContainer}>
|
|
|
|
{content}
|
|
|
|
</View>
|
|
|
|
<Encrypted
|
|
|
|
type={props.type}
|
|
|
|
theme={props.theme}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-30 20:00:31 +00:00
|
|
|
if (props.isIgnored) {
|
|
|
|
content = <Text style={[styles.textInfo, { color: themes[props.theme].auxiliaryText }]}>{I18n.t('Message_Ignored')}</Text>;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
);
|
2020-03-02 20:12:41 +00:00
|
|
|
}, (prevProps, nextProps) => {
|
|
|
|
if (prevProps.isTemp !== nextProps.isTemp) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (prevProps.msg !== nextProps.msg) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-09-11 14:31:38 +00:00
|
|
|
if (prevProps.type !== nextProps.type) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-02 20:12:41 +00:00
|
|
|
if (prevProps.theme !== nextProps.theme) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-09-11 14:31:38 +00:00
|
|
|
if (prevProps.isEncrypted !== nextProps.isEncrypted) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-30 20:00:31 +00:00
|
|
|
if (prevProps.isIgnored !== nextProps.isIgnored) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(prevProps.mentions, nextProps.mentions)) {
|
2020-03-02 20:12:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(prevProps.channels, nextProps.channels)) {
|
2020-03-02 20:12:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
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,
|
2020-09-11 14:31:38 +00:00
|
|
|
isEncrypted: PropTypes.bool,
|
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]),
|
2020-02-21 16:13:05 +00:00
|
|
|
navToRoomInfo: PropTypes.func,
|
2020-09-11 14:31:38 +00:00
|
|
|
useRealName: PropTypes.bool,
|
2020-11-30 20:00:31 +00:00
|
|
|
isIgnored: PropTypes.bool,
|
2020-09-11 14:31:38 +00:00
|
|
|
type: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
Content.displayName = 'MessageContent';
|
|
|
|
|
|
|
|
export default Content;
|