Merge pull request #5127 from Raven24/hpetru-2875-ignore-user-posts

Remove ignored peoples posts without refresh (II)
This commit is contained in:
Jonne Haß 2014-08-18 11:34:45 +02:00
commit ae24495c7d
6 changed files with 54 additions and 20 deletions

View file

@ -34,6 +34,7 @@
* Add rake task to send a mail to all users [#5111](https://github.com/diaspora/diaspora/pull/5111)
* Expose which services are configured in /statistics.json [#5121](https://github.com/diaspora/diaspora/pull/5121)
* In filtered notification views, replace "Mark all as read" with "Mark shown as read" [#5122](https://github.com/diaspora/diaspora/pull/5122)
* When ignoring a user remove his posts from the stream instantly [#5127](https://github.com/diaspora/diaspora/pull/5127)
# 0.4.0.1

View file

@ -20,6 +20,16 @@ var app = {
pages: {},
forms: {},
// global event broker - use event names in the form of "object:action:data"
// [object]: the class of the acting object
// [action]: infinitive verb naming the performed action
// [data]: (optional) unique name or ID of the specific instance
// e.g. "person:ignore:123"
// if your event has to pass more than one datum (singular) - or in case you
// need structured data - specify them as arguments to the `#trigger` call
// e.g. `app.events.trigger('example:event', {more: 'data'})`
events: _.extend({}, Backbone.Events),
user: function(userAttrs) {
if(userAttrs) { return this._user = new app.models.User(userAttrs) }
return this._user || false

View file

@ -27,6 +27,14 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin,
return this.get("author")
},
blockAuthor: function() {
var personId = this.get("author").id;
var block = new app.models.Block();
return block.save({block : {person_id : personId}})
.done(function(){ app.events.trigger('person:block:'+personId); });
},
toggleFavorite : function(options){
this.set({favorite : !this.get("favorite")})

View file

@ -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.events.on('person:block:'+personId, this.remove, this);
this.model.on('remove', this.remove, this);
//subviews
this.commentStreamView = new app.views.CommentStream({model : this.model});
@ -72,20 +75,13 @@ app.views.StreamPost = app.views.Post.extend({
if(evt) { evt.preventDefault(); }
if(!confirm(Diaspora.I18n.t('ignore_user'))) { return }
var personId = this.model.get("author").id;
var block = new app.models.Block();
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);
}
})
}
})
this.model.blockAuthor()
.fail(function() {
Diaspora.page.flashMessages.render({
success: false,
notice: Diaspora.I18n.t('ignore_failed')
});
});
},
remove : function() {

View file

@ -16,6 +16,7 @@ en:
created: "The report was successfully created"
exists: "The report already exists"
ignore_user: "Ignore this user?"
ignore_failed: "Unable to ignore this user"
and: "and"
comma: ","
edit: "Edit"

View file

@ -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.events.trigger('person:block:'+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(){