Chats: parse custom emoji, #386

better-thread-display
Alex Gleason 2020-09-03 13:48:15 -05:00
rodzic e409a7bd38
commit 2db5c67a49
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 11 dodań i 2 usunięć

Wyświetl plik

@ -4,10 +4,14 @@ import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePureComponent from 'react-immutable-pure-component';
import { List as ImmutableList } from 'immutable'; import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import emojify from 'soapbox/features/emoji/emoji'; import emojify from 'soapbox/features/emoji/emoji';
import classNames from 'classnames'; import classNames from 'classnames';
const makeEmojiMap = record => record.get('emojis', ImmutableList()).reduce((map, emoji) => {
return map.set(`:${emoji.get('shortcode')}:`, emoji);
}, ImmutableMap());
const mapStateToProps = (state, { chatMessageIds }) => ({ const mapStateToProps = (state, { chatMessageIds }) => ({
me: state.get('me'), me: state.get('me'),
chatMessages: chatMessageIds.reduce((acc, curr) => { chatMessages: chatMessageIds.reduce((acc, curr) => {
@ -72,6 +76,11 @@ class ChatMessageList extends ImmutablePureComponent {
this.scrollToBottom(); this.scrollToBottom();
} }
parseContent = chatMessage => {
const emojiMap = makeEmojiMap(chatMessage);
return emojify(chatMessage.get('content') || '', emojiMap.toJS());
}
render() { render() {
const { chatMessages, me } = this.props; const { chatMessages, me } = this.props;
@ -88,7 +97,7 @@ class ChatMessageList extends ImmutablePureComponent {
<span <span
title={this.getFormattedTimestamp(chatMessage)} title={this.getFormattedTimestamp(chatMessage)}
className='chat-message__bubble' className='chat-message__bubble'
dangerouslySetInnerHTML={{ __html: emojify(chatMessage.get('content') || '') }} dangerouslySetInnerHTML={{ __html: this.parseContent(chatMessage) }}
ref={this.setRef} ref={this.setRef}
/> />
</div> </div>