Remove posts for ignored person

This commit is contained in:
Hincu Petru 2014-06-25 00:57:47 +00:00
parent b246c7b5ef
commit 653612b74d
4 changed files with 30 additions and 13 deletions

View file

@ -3,6 +3,7 @@
## Refactor ## Refactor
## Bug fixes ## Bug fixes
* Fix which allow to remove ignored users posts without page refresh [#2875](https://github.com/diaspora/diaspora/issues/2875)
## Features ## Features

View file

@ -19,6 +19,7 @@ var app = {
views: {}, views: {},
pages: {}, pages: {},
forms: {}, forms: {},
vent: _.extend({}, Backbone.Events),
user: function(userAttrs) { user: function(userAttrs) {
if(userAttrs) { return this._user = new app.models.User(userAttrs) } if(userAttrs) { return this._user = new app.models.User(userAttrs) }

View file

@ -27,6 +27,9 @@ app.views.StreamPost = app.views.Post.extend({
tooltipSelector : ".timeago, .post_scope, .block_user, .delete", tooltipSelector : ".timeago, .post_scope, .block_user, .delete",
initialize : function(){ 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); this.model.on('remove', this.remove, this);
//subviews //subviews
this.commentStreamView = new app.views.CommentStream({model : this.model}); 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}}, { block.save({block : {person_id : personId}}, {
success : function(){ success : function(){
if(!app.stream) { return } app.vent.trigger('remove:author:posts:'+personId);
_.each(app.stream.posts.models, function(model){
if(model.get("author").id == personId) {
app.stream.posts.remove(model);
}
})
} }
}) })
}, },

View file

@ -1,8 +1,32 @@
describe("app.views.StreamPost", function(){ describe("app.views.StreamPost", function(){
beforeEach(function(){ beforeEach(function(){
this.PostViewClass = app.views.StreamPost 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(){ describe("#render", function(){
var o_embed_cache = { var o_embed_cache = {
"data" : { "data" : {
@ -32,12 +56,6 @@ describe("app.views.StreamPost", function(){
other : "<%= count %> Likes" 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(){ context("reshare", function(){