From 9a2cb1517a9f35f700f50a3870287b55bf97f87d Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem <svbergerem@online.de> Date: Tue, 30 Aug 2016 16:34:06 +0200 Subject: [PATCH] Set participations client side when changing post interactions closes #7040 --- Changelog.md | 5 +++-- .../app/models/post/interactions.js | 3 +++ features/desktop/likes.feature | 6 +++++- .../step_definitions/notifications_steps.rb | 11 ++++++++++ .../app/models/post/interacations_spec.js | 21 ++++++++++++++++--- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Changelog.md b/Changelog.md index f8d6cea31d..9b85d004ea 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,10 +6,11 @@ * Make the session cookies HttpOnly again [#7041](https://github.com/diaspora/diaspora/pull/7041) ## Bug fixes -* Post comments no longer get collapsed when interacting with a post [#7045](https://github.com/diaspora/diaspora/pull/7045) +* Post comments no longer get collapsed when interacting with a post [#7040](https://github.com/diaspora/diaspora/pull/7040) ## Features -* The "subscribe" indicator on a post now gets toggled when you like or rehsare a post [#7045](https://github.com/diaspora/diaspora/pull/7045) +* Deleted comments will be removed when loading more comments [#7045](https://github.com/diaspora/diaspora/pull/7045) +* The "subscribe" indicator on a post now gets toggled when you like or rehsare a post [#7040](https://github.com/diaspora/diaspora/pull/7040) # 0.6.0.0 diff --git a/app/assets/javascripts/app/models/post/interactions.js b/app/assets/javascripts/app/models/post/interactions.js index e837f96bc8..28d6f3a578 100644 --- a/app/assets/javascripts/app/models/post/interactions.js +++ b/app/assets/javascripts/app/models/post/interactions.js @@ -67,6 +67,7 @@ app.models.Post.Interactions = Backbone.Model.extend({ var self = this; this.likes.create({}, { success: function() { + self.post.set({participation: true}); self.trigger("change"); self.set({"likes_count" : self.get("likes_count") + 1}); }, @@ -94,6 +95,7 @@ app.models.Post.Interactions = Backbone.Model.extend({ this.comments.make(text).fail(function () { app.flashMessages.error(Diaspora.I18n.t("failed_to_comment")); }).done(function() { + self.post.set({participation: true}); self.trigger('change'); //updates after sync }); @@ -109,6 +111,7 @@ app.models.Post.Interactions = Backbone.Model.extend({ .done(function(reshare) { app.flashMessages.success(Diaspora.I18n.t("reshares.successful")); interactions.reshares.add(reshare); + interactions.post.set({participation: true}); if (app.stream && /^\/(?:stream|activity|aspects)/.test(app.stream.basePath())) { app.stream.addNow(reshare); } diff --git a/features/desktop/likes.feature b/features/desktop/likes.feature index 3fff3ce567..b32c7af62b 100644 --- a/features/desktop/likes.feature +++ b/features/desktop/likes.feature @@ -14,9 +14,11 @@ Feature: Liking posts And I sign in as "alice@alice.alice" Scenario: Liking and unliking a post from the stream + Then I should not have activated notifications for the post When I like the post "I like unicorns" in the stream Then I should see "Unlike" within ".stream_element .feedback" And I should see a ".likes .media" within "#main_stream .stream_element" + And I should have activated notifications for the post When I unlike the post "I like unicorns" in the stream Then I should see "Like" within ".stream_element .feedback" @@ -25,8 +27,10 @@ Feature: Liking posts Scenario: Liking and unliking a post from a single post page When I open the show page of the "I like unicorns" post - And I click to like the post + Then I should not have activated notifications for the post in the single post view + When I click to like the post Then I should see a ".count" within "#single-post-interactions" + And I should have activated notifications for the post in the single post view When I click to unlike the post Then I should not see a ".count" within "#single-post-interactions" diff --git a/features/step_definitions/notifications_steps.rb b/features/step_definitions/notifications_steps.rb index c61fbf5673..ba12d3403d 100644 --- a/features/step_definitions/notifications_steps.rb +++ b/features/step_definitions/notifications_steps.rb @@ -5,3 +5,14 @@ end When /^I filter notifications by mentions$/ do step %(I follow "Mentioned" within "#notifications_container .list-group") end + +Then /^I should( not)? have activated notifications for the post( in the single post view)?$/ do |negate, spv| + selector = spv ? "#single-post-moderation" : "#main_stream .stream_element" + if negate + expect(find(selector, match: :first)).to have_no_css(".destroy_participation", visible: false) + expect(find(selector, match: :first)).to have_css(".create_participation", visible: false) + else + expect(find(selector, match: :first)).to have_css(".destroy_participation", visible: false) + expect(find(selector, match: :first)).to have_no_css(".create_participation", visible: false) + end +end diff --git a/spec/javascripts/app/models/post/interacations_spec.js b/spec/javascripts/app/models/post/interacations_spec.js index fe5eda94b6..6b2b66e37c 100644 --- a/spec/javascripts/app/models/post/interacations_spec.js +++ b/spec/javascripts/app/models/post/interacations_spec.js @@ -1,6 +1,9 @@ describe("app.models.Post.Interactions", function(){ + var ajaxSuccess = {status: 200, responseText: "{\"id\": 1}"}; + beforeEach(function(){ - this.interactions = factory.post().interactions; + this.post = factory.post(); + this.interactions = this.post.interactions; this.author = factory.author({guid: "loggedInAsARockstar"}); loginAs({guid: "loggedInAsARockstar"}); @@ -30,6 +33,13 @@ describe("app.models.Post.Interactions", function(){ this.interactions.like(); expect(this.interactions.likes.length).toEqual(1); }); + + it("sets the participation flag for the post", function() { + expect(this.post.get("participation")).toBeFalsy(); + this.interactions.like(); + jasmine.Ajax.requests.mostRecent().respondWith(ajaxSuccess); + expect(this.post.get("participation")).toBeTruthy(); + }); }); describe("unlike", function(){ @@ -42,8 +52,6 @@ describe("app.models.Post.Interactions", function(){ }); describe("reshare", function() { - var ajaxSuccess = { status: 200, responseText: "{\"id\": 1}" }; - beforeEach(function(){ this.reshare = this.interactions.post.reshare(); }); @@ -81,6 +89,13 @@ describe("app.models.Post.Interactions", function(){ expect(app.stream.addNow).not.toHaveBeenCalled(); }); }); + + it("sets the participation flag for the post", function() { + expect(this.post.get("participation")).toBeFalsy(); + this.interactions.reshare(); + jasmine.Ajax.requests.mostRecent().respondWith(ajaxSuccess); + expect(this.post.get("participation")).toBeTruthy(); + }); }); describe("userLike", function(){ -- GitLab