diff --git a/src/components/common/helpers/renderText.tsx b/src/components/common/helpers/renderText.tsx index 01bb2cb93..487e17d4d 100644 --- a/src/components/common/helpers/renderText.tsx +++ b/src/components/common/helpers/renderText.tsx @@ -1,12 +1,15 @@ import React from '../../../lib/teact/teact'; -import EMOJI_REGEX, { removeVS16s } from '../../../lib/twemojiRegex'; +import EMOJI_REGEX from '../../../lib/twemojiRegex'; import { TextPart } from '../../../types'; import { RE_LINK_TEMPLATE, RE_MENTION_TEMPLATE } from '../../../config'; import { IS_EMOJI_SUPPORTED } from '../../../util/environment'; import { - fixNonStandardEmoji, handleEmojiLoad, LOADED_EMOJIS, nativeToUnified, + fixNonStandardEmoji, + handleEmojiLoad, + LOADED_EMOJIS, + nativeToUnifiedExtendedWithCache, } from '../../../util/emoji'; import buildClassName from '../../../util/buildClassName'; import { compact } from '../../../util/iteratees'; @@ -103,7 +106,7 @@ function replaceEmojis(textParts: TextPart[], size: 'big' | 'small', type: 'jsx' result.push(parts[0]); return emojis.reduce((emojiResult: TextPart[], emoji, i) => { - const code = nativeToUnified(removeVS16s(emoji)); + const code = nativeToUnifiedExtendedWithCache(emoji); if (!code) return emojiResult; const src = `./img-apple-${size === 'big' ? '160' : '64'}/${code}.png`; const className = buildClassName( diff --git a/src/util/emoji.ts b/src/util/emoji.ts index 46c45a0ac..fcc126089 100644 --- a/src/util/emoji.ts +++ b/src/util/emoji.ts @@ -1,4 +1,5 @@ -import EMOJI_REGEX from '../lib/twemojiRegex'; +import EMOJI_REGEX, { removeVS16s } from '../lib/twemojiRegex'; +import withCache from './withCache'; // Due to the fact that emoji from Apple do not contain some characters, it is necessary to remove them from emoji-data // https://github.com/iamcal/emoji-data/issues/136 @@ -72,6 +73,12 @@ export function nativeToUnified(emoji: string) { return code; } +function nativeToUnifiedExtended(emoji: string) { + return nativeToUnified(removeVS16s(emoji)); +} + +export const nativeToUnifiedExtendedWithCache = withCache(nativeToUnifiedExtended); + export function uncompressEmoji(data: EmojiRawData): EmojiData { const emojiData: EmojiData = { categories: [], emojis: {} };