From 2a3f7869e55d74a13cbd6c7c123e1de6047bad19 Mon Sep 17 00:00:00 2001 From: OtavioStasiak Date: Thu, 10 Oct 2024 15:04:28 -0300 Subject: [PATCH] minor changes --- app/containers/markdown/Emoji.tsx | 10 ++++------ app/containers/markdown/index.tsx | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/containers/markdown/Emoji.tsx b/app/containers/markdown/Emoji.tsx index f9e62d10bf..a372e25c6e 100644 --- a/app/containers/markdown/Emoji.tsx +++ b/app/containers/markdown/Emoji.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { View, Text } from 'react-native'; +import { Text } from 'react-native'; import shortnameToUnicode from '../../lib/methods/helpers/shortnameToUnicode'; import CustomEmoji from '../EmojiPicker/CustomEmoji'; @@ -25,11 +25,9 @@ const Emoji = React.memo(({ literal, isMessageContainsOnlyEmoji, getCustomEmoji, } return ( - - - {emojiUnicode} - - + + {emojiUnicode} + ); }); diff --git a/app/containers/markdown/index.tsx b/app/containers/markdown/index.tsx index 9300d80f25..b00cd0a700 100644 --- a/app/containers/markdown/index.tsx +++ b/app/containers/markdown/index.tsx @@ -67,9 +67,20 @@ const isOnlyEmoji = (str: string) => { return !removeAllEmoji(str).length; }; -const emojiCount = (str: string) => { - const counter = removeSpaces(str).length; +const removeOneEmoji = (str: string) => str.replace(new RegExp(emojiRanges), ''); +const emojiCount = (str: string) => { + str = removeSpaces(str); + let oldLength = 0; + let counter = 0; + + while (oldLength !== str.length) { + oldLength = str.length; + str = removeOneEmoji(str); + if (oldLength !== str.length) { + counter += 1; + } + } return counter; }; @@ -337,7 +348,7 @@ class Markdown extends PureComponent { m = formatHyperlink(m); let ast = parser.parse(m); ast = mergeTextNodes(ast); - this.isMessageContainsOnlyEmoji = isOnlyEmoji(m) && emojiCount(m) <= 6; + this.isMessageContainsOnlyEmoji = isOnlyEmoji(m) && emojiCount(m) <= 3; return this.renderer?.render(ast) || null; } }