From dc260110faa71f4065baf8d9900dddc09abd0a54 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 8 Aug 2014 16:36:53 -0400 Subject: [PATCH] FIX: If editing a reply, the quote button should target the post it was a reply to, not the post you're editing. --- .../javascripts/discourse/models/composer.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/models/composer.js b/app/assets/javascripts/discourse/models/composer.js index 0882b212424..9cee7aa0026 100644 --- a/app/assets/javascripts/discourse/models/composer.js +++ b/app/assets/javascripts/discourse/models/composer.js @@ -305,8 +305,25 @@ Discourse.Composer = Discourse.Model.extend({ }, importQuote: function() { + var postStream = this.get('topic.postStream'), + postId = this.get('post.id'); + + if (!postId && postStream) { + postId = postStream.get('firstPostId'); + } + + // If we're editing a post, fetch the reply when importing a quote + if (this.get('editingPost')) { + var replyToPostNumber = this.get('post.reply_to_post_number'); + if (replyToPostNumber) { + var replyPost = postStream.get('posts').findBy('post_number', replyToPostNumber); + if (replyPost) { + postId = replyPost.get('id'); + } + } + } + // If there is no current post, use the post id from the stream - var postId = this.get('post.id') || this.get('topic.postStream.firstPostId'); if (postId) { this.set('loading', true); var composer = this;