[FIX] Markdown not rendering emojis correctly on server version 5.0.0 (#4343)

This commit is contained in:
Diego Mello 2022-07-06 17:01:33 -03:00 committed by GitHub
parent bf7473c39b
commit 30d3b0b9f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 12 deletions

View File

@ -17,7 +17,7 @@ const styles = StyleSheet.create({
const BigEmoji = ({ value }: IBigEmojiProps) => ( const BigEmoji = ({ value }: IBigEmojiProps) => (
<View style={styles.container}> <View style={styles.container}>
{value.map(block => ( {value.map(block => (
<Emoji value={block.value} isBigEmoji /> <Emoji block={block} isBigEmoji />
))} ))}
</View> </View>
); );

View File

@ -10,20 +10,29 @@ import CustomEmoji from '../../EmojiPicker/CustomEmoji';
import MarkdownContext from './MarkdownContext'; import MarkdownContext from './MarkdownContext';
interface IEmojiProps { interface IEmojiProps {
value: EmojiProps['value']; block: EmojiProps;
isBigEmoji?: boolean; isBigEmoji?: boolean;
} }
const Emoji = ({ value, isBigEmoji }: IEmojiProps) => { const Emoji = ({ block, isBigEmoji }: IEmojiProps) => {
const { theme } = useTheme(); const { theme } = useTheme();
const { baseUrl, getCustomEmoji } = useContext(MarkdownContext); const { baseUrl, getCustomEmoji } = useContext(MarkdownContext);
const emojiUnicode = shortnameToUnicode(`:${value.value}:`);
const emoji = getCustomEmoji?.(value.value); if ('unicode' in block) {
return <Text style={[{ color: themes[theme].bodyText }, isBigEmoji ? styles.textBig : styles.text]}>{block.unicode}</Text>;
}
const emojiToken = block?.shortCode ? `:${block.shortCode}:` : `:${block.value?.value}:`;
const emojiUnicode = shortnameToUnicode(emojiToken);
const emoji = getCustomEmoji?.(block.value?.value);
if (emoji) { if (emoji) {
return <CustomEmoji baseUrl={baseUrl} style={[isBigEmoji ? styles.customEmojiBig : styles.customEmoji]} emoji={emoji} />; return <CustomEmoji baseUrl={baseUrl} style={[isBigEmoji ? styles.customEmojiBig : styles.customEmoji]} emoji={emoji} />;
} }
return <Text style={[{ color: themes[theme].bodyText }, isBigEmoji ? styles.textBig : styles.text]}>{emojiUnicode}</Text>; return (
<Text style={[{ color: themes[theme].bodyText }, isBigEmoji && emojiToken !== emojiUnicode ? styles.textBig : styles.text]}>
{emojiUnicode}
</Text>
);
}; };
export default Emoji; export default Emoji;

View File

@ -48,7 +48,7 @@ const Inline = ({ value }: IParagraphProps) => {
/> />
); );
case 'EMOJI': case 'EMOJI':
return <Emoji value={block.value} />; return <Emoji block={block} />;
case 'MENTION_CHANNEL': case 'MENTION_CHANNEL':
return <Hashtag hashtag={block.value.value} navToRoomInfo={navToRoomInfo} channels={channels} />; return <Hashtag hashtag={block.value.value} navToRoomInfo={navToRoomInfo} channels={channels} />;
case 'INLINE_CODE': case 'INLINE_CODE':

View File

@ -51,7 +51,7 @@
"@react-navigation/elements": "^1.3.3", "@react-navigation/elements": "^1.3.3",
"@react-navigation/native": "6.0.10", "@react-navigation/native": "6.0.10",
"@react-navigation/stack": "6.2.1", "@react-navigation/stack": "6.2.1",
"@rocket.chat/message-parser": "0.30.0", "@rocket.chat/message-parser": "^0.31.14",
"@rocket.chat/sdk": "RocketChat/Rocket.Chat.js.SDK#mobile", "@rocket.chat/sdk": "RocketChat/Rocket.Chat.js.SDK#mobile",
"@rocket.chat/ui-kit": "^0.31.13", "@rocket.chat/ui-kit": "^0.31.13",
"bytebuffer": "^5.0.1", "bytebuffer": "^5.0.1",

View File

@ -4140,10 +4140,10 @@
dependencies: dependencies:
eslint-plugin-import "^2.17.2" eslint-plugin-import "^2.17.2"
"@rocket.chat/message-parser@0.30.0": "@rocket.chat/message-parser@^0.31.14":
version "0.30.0" version "0.31.14"
resolved "https://registry.yarnpkg.com/@rocket.chat/message-parser/-/message-parser-0.30.0.tgz#63a25aa7fa17724d55db80f95f7f8d6a99ae42ff" resolved "https://registry.yarnpkg.com/@rocket.chat/message-parser/-/message-parser-0.31.14.tgz#55042be10a7cd49a7a9a969272bc38897fe1c252"
integrity sha512-pI7ajaojv+GqhQBMnFiBOWerE7zIlJywWFaLzJlIC/wsJ9LgX6YaKY2wqc909nkr+E4qZY1luJ61ErXGGSF9Zw== integrity sha512-WgaWLMCFWcmhRb7cEm1Q8GoD8lgpPuTniG27Qmfw8k86MuZfdHj+cdOfhvkmdNORxx181RhfksTO0k6IkRxh6A==
"@rocket.chat/sdk@RocketChat/Rocket.Chat.js.SDK#mobile": "@rocket.chat/sdk@RocketChat/Rocket.Chat.js.SDK#mobile":
version "1.3.0-mobile" version "1.3.0-mobile"