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';
|
2022-10-21 16:35:26 +00:00
|
|
|
import { messageHaveAuthorName, getInfoMessage } from './utils';
|
2021-09-13 20:41:05 +00:00
|
|
|
import MessageContext from './Context';
|
|
|
|
import { IMessageContent } from './interfaces';
|
2022-04-01 21:52:38 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2022-05-27 17:27:43 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-10-21 16:35:26 +00:00
|
|
|
import { MessageTypesValues } from '../../definitions';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
const Content = React.memo(
|
|
|
|
(props: IMessageContent) => {
|
2022-04-01 21:52:38 +00:00
|
|
|
const { theme } = useTheme();
|
2022-10-21 18:27:55 +00:00
|
|
|
const { user, onLinkPress } = useContext(MessageContext);
|
2022-04-11 18:01:43 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
if (props.isInfo) {
|
|
|
|
// @ts-ignore
|
|
|
|
const infoMessage = getInfoMessage({ ...props });
|
|
|
|
|
|
|
|
const renderMessageContent = (
|
2022-04-01 21:52:38 +00:00
|
|
|
<Text style={[styles.textInfo, { color: themes[theme].auxiliaryText }]} accessibilityLabel={infoMessage}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{infoMessage}
|
|
|
|
</Text>
|
|
|
|
);
|
2022-10-21 16:35:26 +00:00
|
|
|
if (messageHaveAuthorName(props.type as MessageTypesValues)) {
|
2021-09-13 20:41:05 +00:00
|
|
|
return (
|
|
|
|
<Text>
|
|
|
|
<User {...props} /> {renderMessageContent}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return renderMessageContent;
|
|
|
|
}
|
|
|
|
|
2022-04-01 21:52:38 +00:00
|
|
|
const isPreview = props.tmid && !props.isThreadRoom;
|
2021-09-13 20:41:05 +00:00
|
|
|
let content = null;
|
|
|
|
|
2022-03-23 14:37:11 +00:00
|
|
|
if (props.isEncrypted) {
|
2021-09-13 20:41:05 +00:00
|
|
|
content = (
|
2022-04-01 21:52:38 +00:00
|
|
|
<Text style={[styles.textInfo, { color: themes[theme].auxiliaryText }]} accessibilityLabel={I18n.t('Encrypted_message')}>
|
2021-12-02 13:19:15 +00:00
|
|
|
{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 {
|
|
|
|
content = (
|
|
|
|
<Markdown
|
|
|
|
msg={props.msg}
|
2021-10-20 16:32:58 +00:00
|
|
|
md={props.md}
|
2021-09-13 20:41:05 +00:00
|
|
|
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}
|
|
|
|
channels={props.channels}
|
|
|
|
mentions={props.mentions}
|
|
|
|
navToRoomInfo={props.navToRoomInfo}
|
|
|
|
tmid={props.tmid}
|
|
|
|
useRealName={props.useRealName}
|
2022-07-04 18:10:14 +00:00
|
|
|
theme={theme}
|
2021-09-13 20:41:05 +00:00
|
|
|
onLinkPress={onLinkPress}
|
2022-11-11 19:51:57 +00:00
|
|
|
isTranslated={props.isTranslated}
|
2021-09-13 20:41:05 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props.isIgnored) {
|
2022-04-01 21:52:38 +00:00
|
|
|
content = <Text style={[styles.textInfo, { color: themes[theme].auxiliaryText }]}>{I18n.t('Message_Ignored')}</Text>;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.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;
|