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';
|
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';
|
2021-08-20 00:01:17 +00:00
|
|
|
import { SYSTEM_MESSAGE_TYPES_WITH_AUTHOR_NAME, getInfoMessage } 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';
|
2021-08-20 00:01:17 +00:00
|
|
|
import { IMessageContent } from './interfaces';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2021-08-03 22:01:54 +00:00
|
|
|
const Content = React.memo((props: IMessageContent) => {
|
2019-05-20 20:43:50 +00:00
|
|
|
if (props.isInfo) {
|
2021-07-23 01:59:16 +00:00
|
|
|
// @ts-ignore
|
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
|
|
|
}
|
|
|
|
|
2021-07-23 01:59:16 +00:00
|
|
|
const isPreview: any = 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 = (
|
2021-07-23 01:59:16 +00:00
|
|
|
// @ts-ignore
|
2019-07-17 14:06:39 +00:00
|
|
|
<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.displayName = 'MessageContent';
|
|
|
|
|
|
|
|
export default Content;
|