From 5ca1c95d74ae9e32bd012ebe2d4c97f4bfd894be Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 1 Jun 2015 10:29:36 +0930 Subject: [PATCH] Use new replyAction promise implementation --- .../mentions/js/src/post-reply-action.js | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/extensions/mentions/js/src/post-reply-action.js b/extensions/mentions/js/src/post-reply-action.js index 3325867f3..5edef4b61 100644 --- a/extensions/mentions/js/src/post-reply-action.js +++ b/extensions/mentions/js/src/post-reply-action.js @@ -7,24 +7,31 @@ export default function() { var post = this.props.post; if (post.isHidden()) return; + function insertMention(component, quote) { + var mention = '@'+post.user().username()+'#'+post.number()+' '; + + // If the composer is empty, then assume we're starting a new reply. + // In which case we don't want the user to have to confirm if they + // close the composer straight away. + if (!component.content()) { + component.props.originalContent = 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 component = post.discussion().replyAction(); - if (component) { - var quote = window.getSelection().toString(); - var mention = '@'+post.user().username()+'#'+post.number()+' '; + var quote = window.getSelection().toString(); - // If the composer is empty, then assume we're starting a new reply. - // In which case we don't want the user to have to confirm if they - // close the composer straight away. - if (!component.content()) { - component.props.originalContent = mention; - } - - component.editor.insertAtCursor((component.editor.value() ? '\n\n' : '')+(quote ? '> '+mention+quote+'\n\n' : mention)); + 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)); } } })