Add custom emojis to the emoji picker (#5052)

This commit is contained in:
Eugen Rochko
2017-09-23 05:40:28 +02:00
committed by GitHub
parent 293972f716
commit 66126f3021
8 changed files with 91 additions and 2 deletions

View File

@@ -47,3 +47,43 @@ const emojify = (str, customEmojis = {}) => {
};
export default emojify;
export const toCodePoint = (unicodeSurrogates, sep = '-') => {
let r = [], c = 0, p = 0, i = 0;
while (i < unicodeSurrogates.length) {
c = unicodeSurrogates.charCodeAt(i++);
if (p) {
r.push((0x10000 + ((p - 0xD800) << 10) + (c - 0xDC00)).toString(16));
p = 0;
} else if (0xD800 <= c && c <= 0xDBFF) {
p = c;
} else {
r.push(c.toString(16));
}
}
return r.join(sep);
};
export const buildCustomEmojis = customEmojis => {
const emojis = [];
customEmojis.forEach(emoji => {
const shortcode = emoji.get('shortcode');
const url = emoji.get('url');
const name = shortcode.replace(':', '');
emojis.push({
name,
short_names: [name],
text: '',
emoticons: [],
keywords: [name],
imageUrl: url,
});
});
return emojis;
};