diff --git a/Changelog.md b/Changelog.md index d02d636e2ed41a88b9cd4b46c2e8ee0eee7a14dd..437eaf9a4c19f477b560a70c5886ee7093467b8f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -68,6 +68,7 @@ Contributions are very welcome, the hard work is done! * Replace mobile background with color [#6415](https://github.com/diaspora/diaspora/pull/6415) * Port flash messages to backbone [#6395](https://github.com/diaspora/diaspora/6395) * Change login/registration/forgot password button color [#6504](https://github.com/diaspora/diaspora/pull/6504) +* A note regarding ignoring users was added to the failure messages on commenting/liking [#6646](https://github.com/diaspora/diaspora/pull/6646) ## Bug fixes * Destroy Participation when removing interactions with a post [#5852](https://github.com/diaspora/diaspora/pull/5852) diff --git a/app/assets/javascripts/app/models/post/interactions.js b/app/assets/javascripts/app/models/post/interactions.js index 8f15fc33cf1387a28e52dc25d2452e295e09e1cf..e837f96bc8c3b87ea460ab537781ef3fdf707257 100644 --- a/app/assets/javascripts/app/models/post/interactions.js +++ b/app/assets/javascripts/app/models/post/interactions.js @@ -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]; }, @@ -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"); }, @@ -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 }); diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml index fd0325ababd70b1313b0e3c63051fcfd285fbdcf..4e870e0b2b5c5c5b00b19d31dec5dff688fca1b1 100644 --- a/config/locales/javascript/javascript.en.yml +++ b/config/locales/javascript/javascript.en.yml @@ -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: diff --git a/spec/javascripts/app/models/post/interacations_spec.js b/spec/javascripts/app/models/post/interacations_spec.js index 0536b3f1d85016e08a381b63461cec535a406f58..fe5eda94b615ee472909d28934e4c77395fb208d 100644 --- a/spec/javascripts/app/models/post/interacations_spec.js +++ b/spec/javascripts/app/models/post/interacations_spec.js @@ -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(); + }); + }); }); diff --git a/spec/javascripts/app/views/comment_stream_view_spec.js b/spec/javascripts/app/views/comment_stream_view_spec.js index 0c27ecf0c9b6326dd3b4fb64bcfb6606496187a5..cd5ddf0fe14ebd9ac731e46b409e1414cae42ff5 100644 --- a/spec/javascripts/app/views/comment_stream_view_spec.js +++ b/spec/javascripts/app/views/comment_stream_view_spec.js @@ -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"); @@ -123,5 +126,4 @@ describe("app.views.CommentStream", function(){ expect(submitCallback).toHaveBeenCalled(); }); }); - });