cleanup, move code out of big switch statement
parent
60e10364b0
commit
2e71dd3ea8
|
@ -129,29 +129,36 @@ export default class SendMessageComposer extends React.Component {
|
||||||
case 'focus_composer':
|
case 'focus_composer':
|
||||||
this._editorRef.focus();
|
this._editorRef.focus();
|
||||||
break;
|
break;
|
||||||
case 'insert_mention': {
|
case 'insert_mention':
|
||||||
const userId = payload.user_id;
|
this._insertMention(payload.user_id);
|
||||||
const member = this.props.room.getMember(userId);
|
|
||||||
const displayName = member ?
|
|
||||||
member.rawDisplayName : payload.user_id;
|
|
||||||
const userPillPart = this.model.partCreator.userPill(displayName, userId);
|
|
||||||
this.model.insertPartsAt([userPillPart], this._editorRef.getCaret());
|
|
||||||
break;
|
break;
|
||||||
}
|
case 'quote':
|
||||||
case 'quote': {
|
this._insertQuotedMessage(payload.event);
|
||||||
const {partCreator} = this.model;
|
|
||||||
const quoteParts = parseEvent(payload.event, partCreator, { isQuotedMessage: true });
|
|
||||||
// add two newlines
|
|
||||||
quoteParts.push(partCreator.newline());
|
|
||||||
quoteParts.push(partCreator.newline());
|
|
||||||
this.model.insertPartsAt(quoteParts, {offset: 0});
|
|
||||||
// refocus on composer, as we just clicked "Quote"
|
|
||||||
this._editorRef.focus();
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_insertMention(userId) {
|
||||||
|
const member = this.props.room.getMember(userId);
|
||||||
|
const displayName = member ?
|
||||||
|
member.rawDisplayName : userId;
|
||||||
|
const userPillPart = this.model.partCreator.userPill(displayName, userId);
|
||||||
|
this.model.insertPartsAt([userPillPart], this._editorRef.getCaret());
|
||||||
|
// refocus on composer, as we just clicked "Mention"
|
||||||
|
this._editorRef.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
_insertQuotedMessage(event) {
|
||||||
|
const {partCreator} = this.model;
|
||||||
|
const quoteParts = parseEvent(event, partCreator, { isQuotedMessage: true });
|
||||||
|
// add two newlines
|
||||||
|
quoteParts.push(partCreator.newline());
|
||||||
|
quoteParts.push(partCreator.newline());
|
||||||
|
this.model.insertPartsAt(quoteParts, {offset: 0});
|
||||||
|
// refocus on composer, as we just clicked "Quote"
|
||||||
|
this._editorRef.focus();
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="mx_SendMessageComposer" onClick={this.focusComposer} onKeyDown={this._onKeyDown}>
|
<div className="mx_SendMessageComposer" onClick={this.focusComposer} onKeyDown={this._onKeyDown}>
|
||||||
|
|
Loading…
Reference in New Issue