diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index eb22008eb..4832b06b5 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -184,7 +184,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected var selectedPosts = topicController.get('selectedPosts'); Discourse.Post.deleteMany(selectedPosts); - topicController.get('content.posts').removeObjects(selectedPosts); + topicController.get('model.postStream').removePosts(selectedPosts); topicController.toggleMultiSelect(); } }); diff --git a/app/assets/javascripts/discourse/models/post_stream.js b/app/assets/javascripts/discourse/models/post_stream.js index 9a018f709..be6239718 100644 --- a/app/assets/javascripts/discourse/models/post_stream.js +++ b/app/assets/javascripts/discourse/models/post_stream.js @@ -407,6 +407,21 @@ Discourse.PostStream = Em.Object.extend({ return post; }, + /** + Removes posts from the stream. + + @method removePosts + @param {Array} posts the collection of posts to remove + **/ + removePosts: function(posts) { + if (Em.isEmpty(posts)) { return; } + + var postIds = posts.map(function (p) { return p.get('id'); }); + + this.get('stream').removeObjects(postIds); + this.get('posts').removeObjects(posts); + }, + /** Returns a post from the identity map if it's been inserted. diff --git a/test/javascripts/models/post_stream_test.js b/test/javascripts/models/post_stream_test.js index f7eb0e1d7..f99beaa21 100644 --- a/test/javascripts/models/post_stream_test.js +++ b/test/javascripts/models/post_stream_test.js @@ -83,6 +83,27 @@ test('updateFromJson', function() { equal(postStream.get('extra_property'), 12); }); +test("removePosts", function() { + var postStream = buildStream(10000001, [1,2,3]); + + var p1 = Discourse.Post.create({id: 1, post_number: 2}), + p2 = Discourse.Post.create({id: 2, post_number: 3}), + p3 = Discourse.Post.create({id: 3, post_number: 4}); + + postStream.appendPost(p1); + postStream.appendPost(p2); + postStream.appendPost(p3); + + // Removing nothing does nothing + postStream.removePosts(); + equal(postStream.get('posts.length'), 3); + + postStream.removePosts([p1, p3]); + equal(postStream.get('posts.length'), 1); + deepEqual(postStream.get('stream'), [2]); + +}); + test("cancelFilter", function() { var postStream = buildStream(1235); @@ -343,7 +364,6 @@ test('triggerNewPostInStream', function() { test("lastPostLoaded when the id changes", function() { - // This can happen in a race condition between staging a post and it coming through on the // message bus. If the id of a post changes we should reconsider the lastPostLoaded property. var postStream = buildStream(10101, [1, 2]); @@ -355,7 +375,6 @@ test("lastPostLoaded when the id changes", function() { postWithoutId.set('id', 2); ok(postStream.get('lastPostLoaded'), 'the last post is loaded now that the post has an id'); - }); test("comitting and triggerNewPostInStream race condition", function() {