sforkowany z mirror/soapbox
rodzic
2db5c67a49
commit
57fc08771c
|
@ -40,11 +40,24 @@ class ChatBox extends ImmutablePureComponent {
|
||||||
content: '',
|
content: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKeyDown = (e) => {
|
sendMessage = () => {
|
||||||
const { chatId } = this.props;
|
const { chatId } = this.props;
|
||||||
if (e.key === 'Enter') {
|
if (this.state.content.length < 1) return;
|
||||||
this.props.dispatch(sendChatMessage(chatId, this.state));
|
this.props.dispatch(sendChatMessage(chatId, this.state));
|
||||||
this.setState({ content: '' });
|
this.setState({ content: '' });
|
||||||
|
}
|
||||||
|
|
||||||
|
insertLine = () => {
|
||||||
|
const { content } = this.state;
|
||||||
|
this.setState({ content: content + '\n' });
|
||||||
|
}
|
||||||
|
|
||||||
|
handleKeyDown = (e) => {
|
||||||
|
if (e.key === 'Enter' && e.shiftKey) {
|
||||||
|
this.insertLine();
|
||||||
|
e.preventDefault();
|
||||||
|
} else if (e.key === 'Enter') {
|
||||||
|
this.sendMessage();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import { Map as ImmutableMap, 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';
|
||||||
|
import { escape } from 'lodash';
|
||||||
|
|
||||||
const makeEmojiMap = record => record.get('emojis', ImmutableList()).reduce((map, emoji) => {
|
const makeEmojiMap = record => record.get('emojis', ImmutableList()).reduce((map, emoji) => {
|
||||||
return map.set(`:${emoji.get('shortcode')}:`, emoji);
|
return map.set(`:${emoji.get('shortcode')}:`, emoji);
|
||||||
|
@ -76,9 +77,16 @@ class ChatMessageList extends ImmutablePureComponent {
|
||||||
this.scrollToBottom();
|
this.scrollToBottom();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parsePendingContent = content => {
|
||||||
|
return escape(content).replace(/(?:\r\n|\r|\n)/g, '<br>');
|
||||||
|
}
|
||||||
|
|
||||||
parseContent = chatMessage => {
|
parseContent = chatMessage => {
|
||||||
|
const content = chatMessage.get('content') || '';
|
||||||
|
const pending = chatMessage.get('pending', false);
|
||||||
|
const formatted = pending ? this.parsePendingContent(content) : content;
|
||||||
const emojiMap = makeEmojiMap(chatMessage);
|
const emojiMap = makeEmojiMap(chatMessage);
|
||||||
return emojify(chatMessage.get('content') || '', emojiMap.toJS());
|
return emojify(formatted, emojiMap.toJS());
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
Ładowanie…
Reference in New Issue