diff --git a/app/assets/javascripts/discourse/controllers/quote-button.js.es6 b/app/assets/javascripts/discourse/controllers/quote-button.js.es6 index 372728decb6..8b416b6d505 100644 --- a/app/assets/javascripts/discourse/controllers/quote-button.js.es6 +++ b/app/assets/javascripts/discourse/controllers/quote-button.js.es6 @@ -43,8 +43,7 @@ export default Ember.Controller.extend({ if (this.get('buffer') === selectedText) return; // we need to retrieve the post data from the posts collection in the topic controller - const postStream = this.get('controllers.topic.model.postStream'); - this.set('post', postStream.findLoadedPost(postId)); + this.set('postId', postId); this.set('buffer', selectedText); // create a marker element @@ -87,7 +86,17 @@ export default Ember.Controller.extend({ quoteText() { - const post = this.get('post'); + const postStream = this.get('controllers.topic.model.postStream'); + const postId = this.get('postId'); + const post = postStream.findLoadedPost(postId); + + // defer load if needed, if in an expanded replies section + if (!post) { + postStream.loadPost(postId).then(() => { + this.quoteText(); + }); + return; + } // If we can't create a post, delegate to reply as new topic if (!this.get('controllers.topic.model.details.can_create_post')) { @@ -98,7 +107,7 @@ export default Ember.Controller.extend({ const composerController = this.get('controllers.composer'); const composerOpts = { action: Discourse.Composer.REPLY, - draftKey: this.get('post.topic.draft_key') + draftKey: post.get('topic.draft_key') }; if(post.get('post_number') === 1) { diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6 index 2e2dcf079fe..d810723ac32 100644 --- a/app/assets/javascripts/discourse/models/post-stream.js.es6 +++ b/app/assets/javascripts/discourse/models/post-stream.js.es6 @@ -441,6 +441,14 @@ const PostStream = RestModel.extend({ return this.get('postIdentityMap').get(id); }, + loadPost(postId){ + const url = "/posts/" + postId; + const store = this.store; + + return Discourse.ajax(url).then((p) => + this.storePost(store.createRecord('post', p))); + }, + /** Finds and adds a post to the stream by id. Typically this would happen if we receive a message from the message bus indicating there's a new post. We'll only insert it if we currently diff --git a/app/assets/javascripts/discourse/views/embedded-post.js.es6 b/app/assets/javascripts/discourse/views/embedded-post.js.es6 index 4bccf52199c..e6d85a85c2d 100644 --- a/app/assets/javascripts/discourse/views/embedded-post.js.es6 +++ b/app/assets/javascripts/discourse/views/embedded-post.js.es6 @@ -3,6 +3,8 @@ import ScreenTrack from 'discourse/lib/screen-track'; export default Discourse.GroupedView.extend({ templateName: 'embedded-post', classNames: ['reply'], + attributeBindings: ['data-post-id'], + 'data-post-id': Em.computed.alias('content.id'), _startTracking: function() { const post = this.get('content'); diff --git a/app/assets/javascripts/discourse/views/quote-button.js.es6 b/app/assets/javascripts/discourse/views/quote-button.js.es6 index 1d4f7b76062..aa9fb1404bb 100644 --- a/app/assets/javascripts/discourse/views/quote-button.js.es6 +++ b/app/assets/javascripts/discourse/views/quote-button.js.es6 @@ -78,7 +78,7 @@ export default Ember.View.extend({ // breaks if quoting has been disabled by the user if (!Discourse.User.currentProp('enable_quoting')) return; // retrieve the post id from the DOM - const postId = $target.closest('.boxed').data('post-id'); + const postId = $target.closest('.boxed, .reply').data('post-id'); // select the text if (postId) controller.selectText(postId); },