Skip to content

Commit

Permalink
Tell user that the author might ignore them when commenting/liking fa…
Browse files Browse the repository at this point in the history
…iled
  • Loading branch information
Steffen van Bergerem committed Jan 21, 2016
1 parent 6fce81f commit a52c8a2
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 9 deletions.
17 changes: 11 additions & 6 deletions app/assets/javascripts/app/models/post/interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ app.models.Post.Interactions = Backbone.Model.extend({

userLike : function(){
return this.likes.select(function(like){
return like.get("author").guid === app.currentUser.get("guid");
return like.get("author") && like.get("author").guid === app.currentUser.get("guid");
})[0];
},

Expand All @@ -65,10 +65,15 @@ app.models.Post.Interactions = Backbone.Model.extend({

like : function() {
var self = this;
this.likes.create({}, {success : function(){
self.trigger("change");
self.set({"likes_count" : self.get("likes_count") + 1});
}});
this.likes.create({}, {
success: function() {
self.trigger("change");
self.set({"likes_count" : self.get("likes_count") + 1});
},
error: function() {
app.flashMessages.error(Diaspora.I18n.t("failed_to_like"));
}
});

app.instrument("track", "Like");
},
Expand All @@ -87,7 +92,7 @@ app.models.Post.Interactions = Backbone.Model.extend({
var self = this;

this.comments.make(text).fail(function () {
app.flashMessages.error(Diaspora.I18n.t("failed_to_post_message"));
app.flashMessages.error(Diaspora.I18n.t("failed_to_comment"));
}).done(function() {
self.trigger('change'); //updates after sync
});
Expand Down
3 changes: 2 additions & 1 deletion config/locales/javascript/javascript.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ en:
one: "In <%= count %> aspect"
other: "In <%= count %> aspects"
show_more: "Show more"
failed_to_like: "Failed to like!"
failed_to_like: "Failed to like. Maybe the author is ignoring you?"
failed_to_reshare: "Failed to reshare!"
failed_to_comment: "Failed to comment. Maybe the author is ignoring you?"
failed_to_post_message: "Failed to post message!"
failed_to_remove: "Failed to remove the entry!"
comments:
Expand Down
87 changes: 87 additions & 0 deletions spec/javascripts/app/models/post/interacations_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,91 @@ describe("app.models.Post.Interactions", function(){
});
});
});

describe("userLike", function(){
beforeEach(function() {
this.interactions.likes.reset([]);
});

it("returns false if no user liked the post", function() {
expect(this.interactions.userLike()).toBeFalsy();
});

it("returns true if only the current user liked the post", function() {
this.interactions.likes.add(this.userLike);
expect(this.interactions.userLike()).toBeTruthy();
});

it("returns false if only another user liked the post", function() {
var anotherAuthor = factory.author({guid: "anotherAuthor"});
var anotherLike = new app.models.Like({author : anotherAuthor});
this.interactions.likes.add(anotherLike);
expect(this.interactions.userLike()).toBeFalsy();
});

it("returns true if the current user and another user liked the post", function() {
var anotherAuthor = factory.author({guid: "anotherAuthor"});
var anotherLike = new app.models.Like({author : anotherAuthor});
this.interactions.likes.add(anotherLike);
this.interactions.likes.add(this.userLike);
expect(this.interactions.userLike()).toBeTruthy();
});

it("returns false if only a broken like exists", function() {
var brokenLike = new app.models.Like();
this.interactions.likes.add(brokenLike);
expect(this.interactions.userLike()).toBeFalsy();
});

it("returns true if the current user liked the post and there is a broken like", function() {
var brokenLike = new app.models.Like();
this.interactions.likes.add(brokenLike);
this.interactions.likes.add(this.userLike);
expect(this.interactions.userLike()).toBeTruthy();
});
});

describe("userReshare", function(){
beforeEach(function() {
this.interactions.reshares.reset([]);
this.userReshare = new app.models.Reshare({author : this.author});
});

it("returns false if no user reshared the post", function() {
expect(this.interactions.userReshare()).toBeFalsy();
});

it("returns true if only the current user reshared the post", function() {
this.interactions.reshares.add(this.userReshare);
expect(this.interactions.userReshare()).toBeTruthy();
});

it("returns false if only another user reshared the post", function() {
var anotherAuthor = factory.author({guid: "anotherAuthor"});
var anotherReshare = new app.models.Reshare({author : anotherAuthor});
this.interactions.reshares.add(anotherReshare);
expect(this.interactions.userReshare()).toBeFalsy();
});

it("returns true if the current user and another user reshared the post", function() {
var anotherAuthor = factory.author({guid: "anotherAuthor"});
var anotherReshare = new app.models.Reshare({author : anotherAuthor});
this.interactions.reshares.add(anotherReshare);
this.interactions.reshares.add(this.userReshare);
expect(this.interactions.userReshare()).toBeTruthy();
});

it("returns false if only a broken reshare exists", function() {
var brokenReshare = new app.models.Reshare();
this.interactions.reshares.add(brokenReshare);
expect(this.interactions.userReshare()).toBeFalsy();
});

it("returns true if the current user reshared the post and there is a broken reshare", function() {
var brokenReshare = new app.models.Reshare();
this.interactions.reshares.add(brokenReshare);
this.interactions.reshares.add(this.userReshare);
expect(this.interactions.userReshare()).toBeTruthy();
});
});
});
6 changes: 4 additions & 2 deletions spec/javascripts/app/views/comment_stream_view_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ describe("app.views.CommentStream", function(){
});

it("doesn't add the comment to the view, when the request fails", function(){
Diaspora.I18n.load({failed_to_post_message: "posting failed!"});
// disable jshint camelcase for i18n
/* jshint camelcase: false */
Diaspora.I18n.load({failed_to_comment: "posting failed!"});
/* jshint camelcase: true */
this.request.respondWith({status: 500});

expect(this.view.$(".comment-content p").text()).not.toEqual("a new comment");
Expand Down Expand Up @@ -123,5 +126,4 @@ describe("app.views.CommentStream", function(){
expect(submitCallback).toHaveBeenCalled();
});
});

});

0 comments on commit a52c8a2

Please sign in to comment.