import React, { useContext } from 'react';
import { Text, View } from 'react-native';
import { dequal } from 'dequal';
import I18n from '../../i18n';
import styles from './styles';
import Markdown, { MarkdownPreview } from '../markdown';
import User from './User';
import { SYSTEM_MESSAGE_TYPES_WITH_AUTHOR_NAME, getInfoMessage } from './utils';
import MessageContext from './Context';
import { IMessageContent } from './interfaces';
import { useTheme } from '../../theme';
import { themes } from '../../lib/constants';
const Content = React.memo(
(props: IMessageContent) => {
const { theme } = useTheme();
const { baseUrl, user, onLinkPress } = useContext(MessageContext);
if (props.isInfo) {
// @ts-ignore
const infoMessage = getInfoMessage({ ...props });
const renderMessageContent = (
{infoMessage}
);
if (SYSTEM_MESSAGE_TYPES_WITH_AUTHOR_NAME.includes(props.type)) {
return (
{renderMessageContent}
);
}
return renderMessageContent;
}
const isPreview = props.tmid && !props.isThreadRoom;
let content = null;
if (props.isEncrypted) {
content = (
{I18n.t('Encrypted_message')}
);
} else if (isPreview) {
content = ;
} else {
content = (
);
}
if (props.isIgnored) {
content = {I18n.t('Message_Ignored')};
}
return {content};
},
(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;
}
if (!dequal(prevProps.md, nextProps.md)) {
return false;
}
if (!dequal(prevProps.mentions, nextProps.mentions)) {
return false;
}
if (!dequal(prevProps.channels, nextProps.channels)) {
return false;
}
return true;
}
);
Content.displayName = 'MessageContent';
export default Content;