Merge pull request #3600 from matrix-org/jryans/thumb-variation-again

Restore thumbs after variation selector removal
This commit is contained in:
J. Ryan Stinnett 2019-11-07 22:47:15 +02:00 committed by GitHub
commit 3645e4a822
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 12 deletions

View file

@ -48,7 +48,14 @@ const DATA_BY_CATEGORY = {
};
const DATA_BY_EMOJI = {};
const VARIATION_SELECTOR = String.fromCharCode(0xFE0F);
EMOJIBASE.forEach(emoji => {
if (emoji.unicode.includes(VARIATION_SELECTOR)) {
// Clone data into variation-less version
emoji = Object.assign({}, emoji, {
unicode: emoji.unicode.replace(VARIATION_SELECTOR, ""),
});
}
DATA_BY_EMOJI[emoji.unicode] = emoji;
const categoryId = EMOJIBASE_CATEGORY_IDS[emoji.group];
if (DATA_BY_CATEGORY.hasOwnProperty(categoryId)) {
@ -82,7 +89,10 @@ class EmojiPicker extends React.Component {
viewportHeight: 280,
};
this.recentlyUsed = recent.get().map(unicode => DATA_BY_EMOJI[unicode]);
// Convert recent emoji characters to emoji data, removing unknowns.
this.recentlyUsed = recent.get()
.map(unicode => DATA_BY_EMOJI[unicode])
.filter(data => !!data);
this.memoizedDataByCategory = {
recent: this.recentlyUsed,
...DATA_BY_CATEGORY,

View file

@ -16,17 +16,19 @@ limitations under the License.
import React from 'react';
import PropTypes from 'prop-types';
import EMOJIBASE from 'emojibase-data/en/compact.json';
import sdk from '../../../index';
import { _t } from '../../../languageHandler';
import { findEmojiData } from '../../../HtmlUtils';
const QUICK_REACTIONS = ["👍", "👎", "😄", "🎉", "😕", "❤️", "🚀", "👀"];
EMOJIBASE.forEach(emoji => {
const index = QUICK_REACTIONS.indexOf(emoji.unicode);
if (index !== -1) {
QUICK_REACTIONS[index] = emoji;
const QUICK_REACTIONS = ["👍", "👎", "😄", "🎉", "😕", "❤️", "🚀", "👀"].map(emoji => {
const data = findEmojiData(emoji);
if (!data) {
throw new Error(`Emoji ${emoji} doesn't exist in emojibase`);
}
// Prefer our unicode value for quick reactions (which does not have
// variation selectors).
return Object.assign({}, data, { unicode: emoji });
});
class QuickReactions extends React.Component {