1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-11-07 10:46:24 +03:00

Restore thumbs after variation selector removal

This more thorough change adjusts emoji processing to deal with variation
selectors appropriately and revives the missing thumbs.

Regressed by https://github.com/matrix-org/matrix-react-sdk/pull/3598
Fixes https://github.com/vector-im/riot-web/issues/11344
This commit is contained in:
J. Ryan Stinnett
2019-11-07 17:49:25 +00:00
parent 9d180be3c0
commit 3d1a1121b9
3 changed files with 35 additions and 12 deletions

View File

@@ -53,7 +53,6 @@ const ZWJ_REGEX = new RegExp("\u200D|\u2003", "g");
const WHITESPACE_REGEX = new RegExp("\\s", "g");
const BIGEMOJI_REGEX = new RegExp(`^(${EMOJIBASE_REGEX.source})+$`, 'i');
const SINGLE_EMOJI_REGEX = new RegExp(`^(${EMOJIBASE_REGEX.source})$`, 'i');
const COLOR_REGEX = /^#[0-9a-fA-F]{6}$/;
@@ -72,6 +71,21 @@ function mightContainEmoji(str) {
return SURROGATE_PAIR_PATTERN.test(str) || SYMBOL_PATTERN.test(str);
}
/**
* Find emoji data in emojibase by character.
*
* @param {String} char The emoji character
* @return {Object} The emoji data
*/
export function findEmojiData(char) {
// Check against both the char and the char with an empty variation selector
// appended because that's how emojibase stores its base emojis which have
// variations.
// See also https://github.com/vector-im/riot-web/issues/9785.
const emptyVariation = char + VARIATION_SELECTOR;
return EMOJIBASE.find(e => e.unicode === char || e.unicode === emptyVariation);
}
/**
* Returns the shortcode for an emoji character.
*
@@ -79,10 +93,7 @@ function mightContainEmoji(str) {
* @return {String} The shortcode (such as :thumbup:)
*/
export function unicodeToShortcode(char) {
// Check against both the char and the char with an empty variation selector appended because that's how
// emoji-base stores its base emojis which have variations. https://github.com/vector-im/riot-web/issues/9785
const emptyVariation = char + VARIATION_SELECTOR;
const data = EMOJIBASE.find(e => e.unicode === char || e.unicode === emptyVariation);
const data = findEmojiData(char);
return (data && data.shortcodes ? `:${data.shortcodes[0]}:` : '');
}