diff --git a/app/assets/javascripts/discourse/models/composer.js b/app/assets/javascripts/discourse/models/composer.js index efcd437d80d..bce0fc05475 100644 --- a/app/assets/javascripts/discourse/models/composer.js +++ b/app/assets/javascripts/discourse/models/composer.js @@ -446,7 +446,6 @@ Discourse.Composer = Discourse.Model.extend({ title: this.get('title'), category: this.get('categoryId'), topic_id: this.get('topic.id'), - reply_to_post_number: post ? post.get('post_number') : null, imageSizes: opts.imageSizes, cooked: this.getCookedHtml(), reply_count: 0, @@ -465,11 +464,22 @@ Discourse.Composer = Discourse.Model.extend({ auto_close_time: Discourse.Utilities.timestampFromAutocloseString(this.get('auto_close_time')) }); + if(post) { + createdPost.setProperties({ + reply_to_post_number: post.get('post_number'), + reply_to_user: { + username: post.get('username'), + uploaded_avatar_id: post.get('uploaded_avatar_id') + } + }); + } + // If we're in a topic, we can append the post instantly. if (postStream) { // If it's in reply to another post, increase the reply count if (post) { post.set('reply_count', (post.get('reply_count') || 0) + 1); + post.set('replies', []); } if (!postStream.stagePost(createdPost, currentUser)) { diff --git a/app/assets/javascripts/discourse/models/post_stream.js b/app/assets/javascripts/discourse/models/post_stream.js index 4179812ffc5..8b76ddc0857 100644 --- a/app/assets/javascripts/discourse/models/post_stream.js +++ b/app/assets/javascripts/discourse/models/post_stream.js @@ -373,7 +373,6 @@ Discourse.PostStream = Em.Object.extend({ // We can't stage two posts simultaneously if (this.get('stagingPost')) { return false; } - this.set('stagingPost', true); var topic = this.get('topic'); @@ -387,12 +386,14 @@ Discourse.PostStream = Em.Object.extend({ post.setProperties({ post_number: topic.get('highest_post_number'), topic: topic, - created_at: new Date() + created_at: new Date(), + id: -1 }); // If we're at the end of the stream, add the post if (this.get('loadedAllPosts')) { this.appendPost(post); + this.get('stream').addObject(post.get('id')); } return true; @@ -408,6 +409,15 @@ Discourse.PostStream = Em.Object.extend({ if (this.get('loadedAllPosts')) { this.appendPost(post); } + // Correct for a dangling deleted post, if needed + // compensating for message bus pumping in new posts while + // your post is in transit + if(this.get('topic.highest_post_number') < post.get('post_number')){ + this.set('topic.highest_post_number', post.get('post_number')); + } + this.get('stream').removeObject(-1); + this.get('postIdentityMap').set(-1, null); + this.get('stream').addObject(post.get('id')); this.set('stagingPost', false); }, @@ -420,16 +430,19 @@ Discourse.PostStream = Em.Object.extend({ @param {Discourse.Post} the post to undo from the stream **/ undoPost: function(post) { + this.get('stream').removeObject(-1); this.posts.removeObject(post); + this.get('postIdentityMap').set(-1, null); var topic = this.get('topic'); - this.set('stagingPost', false); topic.setProperties({ highest_post_number: (topic.get('highest_post_number') || 0) - 1, posts_count: (topic.get('posts_count') || 0) - 1 }); + + // TODO unfudge reply count on parent post }, /**