Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tell user that the author might ignore them when commenting/liking failed #6646

Merged
merged 1 commit into from
Jan 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});

});