2021-09-13 20:41:05 +00:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
import { Text, View } from 'react-native';
|
|
|
|
import { dequal } from 'dequal';
|
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import styles from './styles';
|
2022-02-17 15:27:01 +00:00
|
|
|
import Markdown, { MarkdownPreview } from '../markdown';
|
2021-09-13 20:41:05 +00:00
|
|
|
import User from './User';
|
|
|
|
import { SYSTEM_MESSAGE_TYPES_WITH_AUTHOR_NAME, getInfoMessage } from './utils';
|
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import MessageContext from './Context';
|
|
|
|
import Encrypted from './Encrypted';
|
|
|
|
import { E2E_MESSAGE_TYPE } from '../../lib/encryption/constants';
|
|
|
|
import { IMessageContent } from './interfaces';
|
|
|
|
|
|
|
|
const Content = React.memo(
|
|
|
|
(props: IMessageContent) => {
|
|
|
|
if (props.isInfo) {
|
|
|
|
// @ts-ignore
|
|
|
|
const infoMessage = getInfoMessage({ ...props });
|
|
|
|
|
|
|
|
const renderMessageContent = (
|
|
|
|
<Text style={[styles.textInfo, { color: themes[props.theme].auxiliaryText }]} accessibilityLabel={infoMessage}>
|
|
|
|
{infoMessage}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (SYSTEM_MESSAGE_TYPES_WITH_AUTHOR_NAME.includes(props.type)) {
|
|
|
|
return (
|
|
|
|
<Text>
|
|
|
|
<User {...props} /> {renderMessageContent}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return renderMessageContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
const isPreview: any = props.tmid && !props.isThreadRoom;
|
|
|
|
let content = null;
|
|
|
|
|
|
|
|
if (props.tmid && !props.msg) {
|
|
|
|
content = <Text style={[styles.text, { color: themes[props.theme].bodyText }]}>{I18n.t('Sent_an_attachment')}</Text>;
|
|
|
|
} else if (props.isEncrypted) {
|
|
|
|
content = (
|
2021-12-02 13:19:15 +00:00
|
|
|
<Text
|
|
|
|
style={[styles.textInfo, { color: themes[props.theme].auxiliaryText }]}
|
|
|
|
accessibilityLabel={I18n.t('Encrypted_message')}>
|
|
|
|
{I18n.t('Encrypted_message')}
|
|
|
|
</Text>
|
2021-09-13 20:41:05 +00:00
|
|
|
);
|
2022-02-17 15:27:01 +00:00
|
|
|
} else if (isPreview) {
|
|
|
|
content = <MarkdownPreview msg={props.msg} />;
|
2021-09-13 20:41:05 +00:00
|
|
|
} else {
|
|
|
|
const { baseUrl, user, onLinkPress } = useContext(MessageContext);
|
|
|
|
content = (
|
|
|
|
<Markdown
|
|
|
|
msg={props.msg}
|
2021-10-20 16:32:58 +00:00
|
|
|
md={props.md}
|
2021-09-13 20:41:05 +00:00
|
|
|
baseUrl={baseUrl}
|
|
|
|
getCustomEmoji={props.getCustomEmoji}
|
2021-10-20 16:32:58 +00:00
|
|
|
enableMessageParser={user.enableMessageParserEarlyAdoption}
|
2021-09-13 20:41:05 +00:00
|
|
|
username={user.username}
|
|
|
|
isEdited={props.isEdited}
|
|
|
|
channels={props.channels}
|
|
|
|
mentions={props.mentions}
|
|
|
|
navToRoomInfo={props.navToRoomInfo}
|
|
|
|
tmid={props.tmid}
|
|
|
|
useRealName={props.useRealName}
|
|
|
|
theme={props.theme}
|
|
|
|
onLinkPress={onLinkPress}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props.isIgnored) {
|
|
|
|
content = <Text style={[styles.textInfo, { color: themes[props.theme].auxiliaryText }]}>{I18n.t('Message_Ignored')}</Text>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <View style={props.isTemp && styles.temp}>{content}</View>;
|
|
|
|
},
|
|
|
|
(prevProps, nextProps) => {
|
|
|
|
if (prevProps.isTemp !== nextProps.isTemp) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (prevProps.msg !== nextProps.msg) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (prevProps.type !== nextProps.type) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (prevProps.theme !== nextProps.theme) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (prevProps.isEncrypted !== nextProps.isEncrypted) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (prevProps.isIgnored !== nextProps.isIgnored) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-10-20 16:32:58 +00:00
|
|
|
if (!dequal(prevProps.md, nextProps.md)) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
if (!dequal(prevProps.mentions, nextProps.mentions)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!dequal(prevProps.channels, nextProps.channels)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
Content.displayName = 'MessageContent';
|
|
|
|
|
|
|
|
export default Content;
|