{
render() {
- const {
- unicode = "",
- annotation = "",
- } = this.props.emoji;
- const shortcode = getShortcodes(this.props.emoji)[0];
+ const { unicode, annotation, shortcodes: [shortcode] } = this.props.emoji;
return (
diff --git a/src/components/views/emojipicker/QuickReactions.tsx b/src/components/views/emojipicker/QuickReactions.tsx
index 2d78e3e4cf..9321450fc1 100644
--- a/src/components/views/emojipicker/QuickReactions.tsx
+++ b/src/components/views/emojipicker/QuickReactions.tsx
@@ -18,7 +18,7 @@ limitations under the License.
import React from 'react';
import { _t } from '../../../languageHandler';
-import { getEmojiFromUnicode, getShortcodes, IEmoji } from "../../../emoji";
+import { getEmojiFromUnicode, IEmoji } from "../../../emoji";
import Emoji from "./Emoji";
import { replaceableComponent } from "../../../utils/replaceableComponent";
@@ -62,7 +62,7 @@ class QuickReactions extends React.Component {
};
render() {
- const shortcode = this.state.hover ? getShortcodes(this.state.hover)[0] : undefined;
+ const shortcode = this.state.hover?.shortcodes?.[0];
return (
diff --git a/src/emoji.ts b/src/emoji.ts
index ac4de654f7..fe9e52d35f 100644
--- a/src/emoji.ts
+++ b/src/emoji.ts
@@ -22,26 +22,19 @@ export interface IEmoji {
group?: number;
hexcode: string;
order?: number;
+ shortcodes: string[];
tags?: string[];
unicode: string;
emoticon?: string;
-}
-
-interface IEmojiWithFilterString extends IEmoji {
- filterString?: string;
+ filterString: string;
}
// The unicode is stored without the variant selector
-const UNICODE_TO_EMOJI = new Map(); // not exported as gets for it are handled by getEmojiFromUnicode
-export const EMOTICON_TO_EMOJI = new Map();
+const UNICODE_TO_EMOJI = new Map(); // not exported as gets for it are handled by getEmojiFromUnicode
+export const EMOTICON_TO_EMOJI = new Map();
export const getEmojiFromUnicode = unicode => UNICODE_TO_EMOJI.get(stripVariation(unicode));
-const toArray = (shortcodes?: string | string[]): string[] =>
- typeof shortcodes === "string" ? [shortcodes] : (shortcodes ?? []);
-export const getShortcodes = (emoji: IEmoji): string[] =>
- toArray(SHORTCODES[emoji.hexcode]);
-
const EMOJIBASE_GROUP_ID_TO_CATEGORY = [
"people", // smileys
"people", // actually people
@@ -69,17 +62,24 @@ export const DATA_BY_CATEGORY = {
const ZERO_WIDTH_JOINER = "\u200D";
// Store various mappings from unicode/emoticon/shortcode to the Emoji objects
-EMOJIBASE.forEach((emoji: IEmojiWithFilterString) => {
- const shortcodes = getShortcodes(emoji);
+export const EMOJI: IEmoji[] = EMOJIBASE.map(emojiData => {
+ const shortcodeData = SHORTCODES[emojiData.hexcode];
+ // Homogenize shortcodes by ensuring that everything is an array
+ const shortcodes = typeof shortcodeData === "string" ? [shortcodeData] : (shortcodeData ?? []);
+
+ const emoji: IEmoji = {
+ ...emojiData,
+ shortcodes,
+ // This is used as the string to match the query against when filtering emojis
+ filterString: (`${emojiData.annotation}\n${shortcodes.join('\n')}}\n${emojiData.emoticon || ''}\n` +
+ `${emojiData.unicode.split(ZERO_WIDTH_JOINER).join("\n")}`).toLowerCase(),
+ };
+
const categoryId = EMOJIBASE_GROUP_ID_TO_CATEGORY[emoji.group];
if (DATA_BY_CATEGORY.hasOwnProperty(categoryId)) {
DATA_BY_CATEGORY[categoryId].push(emoji);
}
- // This is used as the string to match the query against when filtering emojis
- emoji.filterString = (`${emoji.annotation}\n${shortcodes.join('\n')}}\n${emoji.emoticon || ''}\n` +
- `${emoji.unicode.split(ZERO_WIDTH_JOINER).join("\n")}`).toLowerCase();
-
// Add mapping from unicode to Emoji object
// The 'unicode' field that we use in emojibase has either
// VS15 or VS16 appended to any characters that can take
@@ -93,6 +93,8 @@ EMOJIBASE.forEach((emoji: IEmojiWithFilterString) => {
// Add mapping from emoticon to Emoji object
EMOTICON_TO_EMOJI.set(emoji.emoticon, emoji);
}
+
+ return emoji;
});
/**
@@ -106,5 +108,3 @@ EMOJIBASE.forEach((emoji: IEmojiWithFilterString) => {
function stripVariation(str) {
return str.replace(/[\uFE00-\uFE0F]$/, "");
}
-
-export const EMOJI: IEmoji[] = EMOJIBASE;