FIX: when replying to a expanded reply, correctly attribute author

This commit is contained in:
Sam 2015-09-24 15:32:09 +10:00 committed by Robin Ward
parent 80893a69ba
commit d7f2933743
4 changed files with 24 additions and 5 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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');

View File

@ -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);
},