Use new replyAction promise implementation

This commit is contained in:
Toby Zerner
2015-06-01 10:29:36 +09:30
parent eb69be366a
commit 5ca1c95d74

View File

@ -7,14 +7,7 @@ export default function() {
var post = this.props.post; var post = this.props.post;
if (post.isHidden()) return; if (post.isHidden()) return;
items.add('reply', function insertMention(component, quote) {
ActionButton.component({
icon: 'reply',
label: 'Reply',
onclick: () => {
var component = post.discussion().replyAction();
if (component) {
var quote = window.getSelection().toString();
var mention = '@'+post.user().username()+'#'+post.number()+' '; var mention = '@'+post.user().username()+'#'+post.number()+' ';
// If the composer is empty, then assume we're starting a new reply. // If the composer is empty, then assume we're starting a new reply.
@ -24,7 +17,21 @@ export default function() {
component.props.originalContent = mention; component.props.originalContent = mention;
} }
component.editor.insertAtCursor((component.editor.value() ? '\n\n' : '')+(quote ? '> '+mention+quote+'\n\n' : mention)); component.editor.insertAtCursor((component.editor.getSelectionRange()[0] > 0 ? '\n\n' : '')+(quote ? '> '+mention+quote.trim().replace(/\n/g, '\n> ')+'\n\n' : mention));
}
items.add('reply',
ActionButton.component({
icon: 'reply',
label: 'Reply',
onclick: () => {
var quote = window.getSelection().toString();
var component = app.composer.component;
if (component && component.props.post && component.props.post.discussion() === post.discussion()) {
insertMention(component, quote);
} else {
post.discussion().replyAction().then(component => insertMention(component, quote));
} }
} }
}) })