diff --git a/Changelog.md b/Changelog.md index e4774b931..51f773311 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ ## Refactor ## Bug fixes +* Fix which allow to remove ignored users posts without page refresh [#2875](https://github.com/diaspora/diaspora/issues/2875) ## Features diff --git a/app/assets/javascripts/app/app.js b/app/assets/javascripts/app/app.js index 2c9099bf7..6ed0a220d 100644 --- a/app/assets/javascripts/app/app.js +++ b/app/assets/javascripts/app/app.js @@ -19,6 +19,7 @@ var app = { views: {}, pages: {}, forms: {}, + vent: _.extend({}, Backbone.Events), user: function(userAttrs) { if(userAttrs) { return this._user = new app.models.User(userAttrs) } diff --git a/app/assets/javascripts/app/views/stream_post_views.js b/app/assets/javascripts/app/views/stream_post_views.js index ef557362d..1699f326d 100644 --- a/app/assets/javascripts/app/views/stream_post_views.js +++ b/app/assets/javascripts/app/views/stream_post_views.js @@ -27,6 +27,9 @@ app.views.StreamPost = app.views.Post.extend({ tooltipSelector : ".timeago, .post_scope, .block_user, .delete", initialize : function(){ + var personId = this.model.get('author').id; + app.vent.on('remove:author:posts:'+personId, this.remove, this); + this.model.on('remove', this.remove, this); //subviews this.commentStreamView = new app.views.CommentStream({model : this.model}); @@ -77,13 +80,7 @@ app.views.StreamPost = app.views.Post.extend({ block.save({block : {person_id : personId}}, { success : function(){ - if(!app.stream) { return } - - _.each(app.stream.posts.models, function(model){ - if(model.get("author").id == personId) { - app.stream.posts.remove(model); - } - }) + app.vent.trigger('remove:author:posts:'+personId); } }) }, diff --git a/spec/javascripts/app/views/stream_post_spec.js b/spec/javascripts/app/views/stream_post_spec.js index d6459dfde..a5793d9ab 100644 --- a/spec/javascripts/app/views/stream_post_spec.js +++ b/spec/javascripts/app/views/stream_post_spec.js @@ -1,8 +1,32 @@ describe("app.views.StreamPost", function(){ beforeEach(function(){ this.PostViewClass = app.views.StreamPost + + var posts = $.parseJSON(spec.readFixture("stream_json")); + this.collection = new app.collections.Posts(posts); + this.statusMessage = this.collection.models[0]; + this.reshare = this.collection.models[1]; }) + describe("events", function(){ + var _PostViewClass = undefined; + var author_id = undefined; + + beforeEach(function(){ + _PostViewClass = this.PostViewClass; + authorId = this.statusMessage.get('author').id; + }); + + describe("remove posts for blocked person", function(){ + it("setup remove:author:posts:#{id} to #remove", function(){ + spyOn(_PostViewClass.prototype, 'remove'); + view = new _PostViewClass({model : this.statusMessage}); + app.vent.trigger('remove:author:posts:'+authorId); + expect(_PostViewClass.prototype.remove).toHaveBeenCalled(); + }); + }); + }); + describe("#render", function(){ var o_embed_cache = { "data" : { @@ -32,12 +56,6 @@ describe("app.views.StreamPost", function(){ other : "<%= count %> Likes" } }}) - - var posts = $.parseJSON(spec.readFixture("stream_json")); - - this.collection = new app.collections.Posts(posts); - this.statusMessage = this.collection.models[0]; - this.reshare = this.collection.models[1]; }) context("reshare", function(){