diff --git a/app/javascript/mastodon/emoji.js b/app/javascript/mastodon/emoji.js index 407b21b4b..39123768a 100644 --- a/app/javascript/mastodon/emoji.js +++ b/app/javascript/mastodon/emoji.js @@ -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; +}; diff --git a/app/javascript/mastodon/features/compose/components/compose_form.js b/app/javascript/mastodon/features/compose/components/compose_form.js index bb747b611..d31041061 100644 --- a/app/javascript/mastodon/features/compose/components/compose_form.js +++ b/app/javascript/mastodon/features/compose/components/compose_form.js @@ -12,7 +12,7 @@ import Collapsable from '../../../components/collapsable'; import SpoilerButtonContainer from '../containers/spoiler_button_container'; import PrivacyDropdownContainer from '../containers/privacy_dropdown_container'; import SensitiveButtonContainer from '../containers/sensitive_button_container'; -import EmojiPickerDropdown from './emoji_picker_dropdown'; +import EmojiPickerDropdown from '../containers/emoji_picker_dropdown_container'; import UploadFormContainer from '../containers/upload_form_container'; import WarningContainer from '../containers/warning_container'; import { isMobile } from '../../../is_mobile'; diff --git a/app/javascript/mastodon/features/compose/components/emoji_picker_dropdown.js b/app/javascript/mastodon/features/compose/components/emoji_picker_dropdown.js index 43e175be5..f55d59e03 100644 --- a/app/javascript/mastodon/features/compose/components/emoji_picker_dropdown.js +++ b/app/javascript/mastodon/features/compose/components/emoji_picker_dropdown.js @@ -4,6 +4,8 @@ import { defineMessages, injectIntl } from 'react-intl'; import { EmojiPicker as EmojiPickerAsync } from '../../ui/util/async-components'; import { Overlay } from 'react-overlays'; import classNames from 'classnames'; +import ImmutablePropTypes from 'react-immutable-proptypes'; +import { buildCustomEmojis } from '../../../emoji'; const messages = defineMessages({ emoji: { id: 'emoji_button.label', defaultMessage: 'Insert emoji' }, @@ -130,6 +132,7 @@ class ModifierPicker extends React.PureComponent { class EmojiPickerMenu extends React.PureComponent { static propTypes = { + custom_emojis: ImmutablePropTypes.list, loading: PropTypes.bool, onClose: PropTypes.func.isRequired, onPick: PropTypes.func.isRequired, @@ -194,6 +197,10 @@ class EmojiPickerMenu extends React.PureComponent { } handleClick = emoji => { + if (!emoji.native) { + emoji.native = emoji.colons; + } + this.props.onClose(); this.props.onPick(emoji); } @@ -225,6 +232,7 @@ class EmojiPickerMenu extends React.PureComponent { return (