vn-verdnaturachat/app/containers/message/Content.tsx

122 lines
3.2 KiB
TypeScript
Raw Normal View History

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 { themes } from '../../constants/colors';
import MessageContext from './Context';
import Encrypted from './Encrypted';
import { E2E_MESSAGE_TYPE } from '../../lib/constants';
import { IMessageContent } from './interfaces';
import { useTheme } from '../../theme';
const Content = React.memo(
(props: IMessageContent) => {
const { theme } = useTheme();
if (props.isInfo) {
// @ts-ignore
const infoMessage = getInfoMessage({ ...props });
const renderMessageContent = (
<Text style={[styles.textInfo, { color: themes[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 = props.tmid && !props.isThreadRoom;
let content = null;
if (props.isEncrypted) {
content = (
<Text style={[styles.textInfo, { color: themes[theme].auxiliaryText }]} accessibilityLabel={I18n.t('Encrypted_message')}>
{I18n.t('Encrypted_message')}
</Text>
);
} else if (isPreview) {
content = <MarkdownPreview msg={props.msg} />;
} else {
const { baseUrl, user, onLinkPress } = useContext(MessageContext);
content = (
<Markdown
msg={props.msg}
[NEW] Support new message parser (#3313) * Add message parser to profile view and db * Add md to db * Remove changes to Xcode project * Remove message-parser lib and add enable message parser field to User model * Fix message parser * Remove admin enableMessageParserEarlyAdoption * Add NewMarkdown component * Remove NewMarkdown component and add specific components for new message parser * Add new parser components * Fix BigEmoji * Updated components and added more Code components * update components and add storybooks * Update Code component and add it to storybooks * Update Mention component * Minor tweaks * Add server message parser validation * Renamed folder, add @rocket.chat/message-parser, migrate some files to TypeScript * Migrate components to TypeScript and fix styling * Change interfaces and add TaskListComponent and styles * Fix new markdown and styles * Fix inlinecode * Stop using server setting * Use enableMessageParserEarlyAdoption on mapStateToProps * Remove React.FC * add link to bold, italic and strike * Update parser components * Fix missing components * Minor tweak * Fix lint and add getCustomEmojis * Fix customEmojis * Update emojis * Minor tweak * disconnect markdown from store * Use @rocket.chat/message-parser@0.30.0 * Fix link style * Unify lists and styles * Remove style prop * Use big emoji as a normal token * Remove unnecessary memo * Fix code styles * Update tests * Conditionally create renderer * Use Context instead of prop drill * Fix Link component * Fix plain text regression and update tests Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-10-20 16:32:58 +00:00
md={props.md}
baseUrl={baseUrl}
getCustomEmoji={props.getCustomEmoji}
[NEW] Support new message parser (#3313) * Add message parser to profile view and db * Add md to db * Remove changes to Xcode project * Remove message-parser lib and add enable message parser field to User model * Fix message parser * Remove admin enableMessageParserEarlyAdoption * Add NewMarkdown component * Remove NewMarkdown component and add specific components for new message parser * Add new parser components * Fix BigEmoji * Updated components and added more Code components * update components and add storybooks * Update Code component and add it to storybooks * Update Mention component * Minor tweaks * Add server message parser validation * Renamed folder, add @rocket.chat/message-parser, migrate some files to TypeScript * Migrate components to TypeScript and fix styling * Change interfaces and add TaskListComponent and styles * Fix new markdown and styles * Fix inlinecode * Stop using server setting * Use enableMessageParserEarlyAdoption on mapStateToProps * Remove React.FC * add link to bold, italic and strike * Update parser components * Fix missing components * Minor tweak * Fix lint and add getCustomEmojis * Fix customEmojis * Update emojis * Minor tweak * disconnect markdown from store * Use @rocket.chat/message-parser@0.30.0 * Fix link style * Unify lists and styles * Remove style prop * Use big emoji as a normal token * Remove unnecessary memo * Fix code styles * Update tests * Conditionally create renderer * Use Context instead of prop drill * Fix Link component * Fix plain text regression and update tests Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-10-20 16:32:58 +00:00
enableMessageParser={user.enableMessageParserEarlyAdoption}
username={user.username}
isEdited={props.isEdited}
channels={props.channels}
mentions={props.mentions}
navToRoomInfo={props.navToRoomInfo}
tmid={props.tmid}
useRealName={props.useRealName}
theme={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} />
</View>
);
}
if (props.isIgnored) {
content = <Text style={[styles.textInfo, { color: themes[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.isEncrypted !== nextProps.isEncrypted) {
return false;
}
if (prevProps.isIgnored !== nextProps.isIgnored) {
return false;
}
[NEW] Support new message parser (#3313) * Add message parser to profile view and db * Add md to db * Remove changes to Xcode project * Remove message-parser lib and add enable message parser field to User model * Fix message parser * Remove admin enableMessageParserEarlyAdoption * Add NewMarkdown component * Remove NewMarkdown component and add specific components for new message parser * Add new parser components * Fix BigEmoji * Updated components and added more Code components * update components and add storybooks * Update Code component and add it to storybooks * Update Mention component * Minor tweaks * Add server message parser validation * Renamed folder, add @rocket.chat/message-parser, migrate some files to TypeScript * Migrate components to TypeScript and fix styling * Change interfaces and add TaskListComponent and styles * Fix new markdown and styles * Fix inlinecode * Stop using server setting * Use enableMessageParserEarlyAdoption on mapStateToProps * Remove React.FC * add link to bold, italic and strike * Update parser components * Fix missing components * Minor tweak * Fix lint and add getCustomEmojis * Fix customEmojis * Update emojis * Minor tweak * disconnect markdown from store * Use @rocket.chat/message-parser@0.30.0 * Fix link style * Unify lists and styles * Remove style prop * Use big emoji as a normal token * Remove unnecessary memo * Fix code styles * Update tests * Conditionally create renderer * Use Context instead of prop drill * Fix Link component * Fix plain text regression and update tests Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-10-20 16:32:58 +00:00
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;