kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Chats: parse custom emoji, #386
rodzic
e409a7bd38
commit
2db5c67a49
|
@ -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>
|
||||||
|
|
Ładowanie…
Reference in New Issue