From c9d49c89a6143c3f2caa4f76f789e206f2d9b165 Mon Sep 17 00:00:00 2001
From: Steffen van Bergerem <svbergerem@omgsrsly.net>
Date: Sat, 19 Nov 2016 14:36:56 +0100
Subject: [PATCH] Always show mobile reaction counts

fixes #5829
---
 .../javascripts/mobile/mobile_comments.js     |  8 +++----
 app/assets/stylesheets/mobile/comments.scss   | 22 ++++++++---------
 app/helpers/mobile_helper.rb                  | 10 ++++----
 app/views/shared/_stream_element.mobile.haml  |  4 ++--
 config/locales/diaspora/en.yml                |  5 ----
 config/locales/javascript/javascript.en.yml   | 10 ++++----
 features/mobile/reactions.feature             | 24 +++++++++----------
 .../mobile/mobile_comments_spec.js            |  8 +++----
 8 files changed, 40 insertions(+), 51 deletions(-)

diff --git a/app/assets/javascripts/mobile/mobile_comments.js b/app/assets/javascripts/mobile/mobile_comments.js
index e753b70f2b..d680d5dd93 100644
--- a/app/assets/javascripts/mobile/mobile_comments.js
+++ b/app/assets/javascripts/mobile/mobile_comments.js
@@ -189,11 +189,11 @@
     increaseReactionCount: function(bottomBar) {
       var toggleReactionsLink = bottomBar.find(".show-comments").first();
       var count = toggleReactionsLink.text().match(/.*(\d+).*/);
-      var text = "";
+      count = parseInt(count, 10);
+      var text = Diaspora.I18n.t("stream.comments", {count: count + 1});
 
       // No previous comment
-      if(!count){
-        text = Diaspora.I18n.t("stream.reactions", {count: 1});
+      if (count === 0) {
         var parent = toggleReactionsLink.parent();
         var postGuid = bottomBar.parents(".stream-element").data("guid");
 
@@ -204,8 +204,6 @@
         bottomBar.removeClass("inactive").addClass("active");
       }
       else {
-        count = parseInt(count, 10) + 1;
-        text = Diaspora.I18n.t("stream.reactions", {count: count});
         toggleReactionsLink.html(text + "<i class='entypo-chevron-up'/>");
       }
     },
diff --git a/app/assets/stylesheets/mobile/comments.scss b/app/assets/stylesheets/mobile/comments.scss
index e77bf196aa..7588a47fea 100644
--- a/app/assets/stylesheets/mobile/comments.scss
+++ b/app/assets/stylesheets/mobile/comments.scss
@@ -38,29 +38,25 @@
   }
 
   .post-stats {
-    top: -5px;
     float: right;
     position: relative;
     display: flex;
-    margin-bottom: -15px;
 
     .count {
-      background-color: $background-grey;
-      text-align: center;
+      line-height: 22px;
+      margin-left: 5px;
       z-index: 2;
     }
 
     .icon-count-group {
       display: flex;
-      flex-flow: column;
-      justify-content: center;
       margin: 0 7px;
     }
 
     [class^="entypo"] {
       color: $text-grey;
       font-size: 24px;
-      height: 28px;
+      line-height: 24px;
       margin: 0;
       width: 100%;
     }
@@ -77,21 +73,23 @@
   }
 
   .post-action {
-    height: 28px;
-
     .disabled { color: $medium-gray; }
   }
 
   .add-comment-switcher { padding-top: 10px; }
 
-  &.inactive .post-stats .count,
-  &.inactive .comment-container {
-    display: none;
+  &.inactive {
+    padding-bottom: 8px;
+
+    .comment-container {
+      display: none;
+    }
   }
 }
 
 .stream-element .comments {
   margin: 0;
+  margin-top: 10px;
   padding: 0;
   width: 100%;
 
diff --git a/app/helpers/mobile_helper.rb b/app/helpers/mobile_helper.rb
index 23cc959fbb..818568bc7d 100644
--- a/app/helpers/mobile_helper.rb
+++ b/app/helpers/mobile_helper.rb
@@ -36,20 +36,20 @@ module MobileHelper
     link_to "", new_post_comment_path(post), class: "entypo-comment comment-action inactive"
   end
 
-  def reactions_link(post, klass="")
-    reactions_count = post.comments_count + post.likes_count
+  def show_comments_link(post, klass="")
     if klass == "active"
       entypo_class = "entypo-chevron-up"
     else
       entypo_class = "entypo-chevron-down"
     end
-    if reactions_count > 0
-      link_to "#{t('reactions', count: reactions_count)}<i class='#{entypo_class}'></i>".html_safe,
+
+    if post.comments_count > 0
+      link_to "#{t('admins.stats.comments', count: post.comments_count)}<i class='#{entypo_class}'></i>".html_safe,
               post_comments_path(post, format: "mobile"),
               class: "show-comments #{klass}"
     else
       html = "<span class='show-comments'>"
-      html << "#{t('reactions', count: reactions_count)}"
+      html << t("admins.stats.comments", count: post.comments_count)
       html << "</span>"
     end
   end
diff --git a/app/views/shared/_stream_element.mobile.haml b/app/views/shared/_stream_element.mobile.haml
index 0e899d0899..4fd5aba2c0 100644
--- a/app/views/shared/_stream_element.mobile.haml
+++ b/app/views/shared/_stream_element.mobile.haml
@@ -23,13 +23,13 @@
     = render partial: "comments/post_stats", locals: {post: post}
 
     - if defined?(expanded_info) && expanded_info
-      != reactions_link(post, "active")
+      != show_comments_link(post, "active")
       .comment-container
         %ul.comments
           = render partial: "comments/comment", collection: post.comments.for_a_stream, locals: {post: post}
 
     - else
-      != reactions_link(post)
+      != show_comments_link(post)
 
     .ajax-loader.hidden
       .loader
diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml
index 4ab60f12d2..6fa0ba6889 100644
--- a/config/locales/diaspora/en.yml
+++ b/config/locales/diaspora/en.yml
@@ -246,11 +246,6 @@ en:
       comment: "Comment"
       commenting: "Commenting..."
 
-  reactions:
-    zero: "No reactions"
-    one: "1 reaction"
-    other: "%{count} reactions"
-
   contacts:
     index:
       start_a_conversation: "Start a conversation"
diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml
index a4583ee4f7..bea00ddeee 100644
--- a/config/locales/javascript/javascript.en.yml
+++ b/config/locales/javascript/javascript.en.yml
@@ -281,6 +281,11 @@ en:
         one: "<%= count %> Reshare"
         other: "<%= count %> Reshares"
 
+      comments:
+        zero: "<%= count %> comments"
+        one: "<%= count %> comment"
+        other: "<%= count %> comments"
+
       more_comments:
         zero: "Show <%= count %> more comments"
         one: "Show <%= count %> more comment"
@@ -299,11 +304,6 @@ en:
         follow_error: "Couldn’t follow #<%= tag %> :("
         stop_following_error: "Couldn’t stop following #<%= tag %> :("
 
-      reactions:
-        zero: "<%= count%> reactions"
-        one: "<%= count%> reaction"
-        other: "<%= count%> reactions"
-
     header:
       home: "Home"
       profile: "Profile"
diff --git a/features/mobile/reactions.feature b/features/mobile/reactions.feature
index 5f15cde82b..81133e8714 100644
--- a/features/mobile/reactions.feature
+++ b/features/mobile/reactions.feature
@@ -14,23 +14,21 @@ Feature: reactions mobile post
     And I sign in as "bob@bob.bob" on the mobile website
 
   Scenario: like on a mobile post
-    When I should see "No reactions" within ".show-comments"
-    And I click on selector "a.like-action.inactive"
+    When I click on selector "a.like-action.inactive"
     Then I should see a "a.like-action.active"
+    And I should see "1" within ".like-count"
     When I go to the stream page
-    And I should see "1 reaction" within ".show-comments"
-    And I click on selector "a.show-comments"
-    Then I should see "1" within ".like-count"
+    Then I should see a "a.like-action.active"
+    And I should see "1" within ".like-count"
 
   Scenario: liking from the profile view
     When I am on "alice@alice.alice"'s page
-    Then I should see "No reactions" within ".show-comments"
     And I click on selector "a.like-action.inactive"
     Then I should see a "a.like-action.active"
+    And I should see "1" within ".like-count"
     When I go to the stream page
-    And I should see "1 reaction" within ".show-comments"
-    And I click on selector "a.show-comments"
-    Then I should see "1" within ".like-count"
+    Then I should see a "a.like-action.active"
+    And I should see "1" within ".like-count"
 
   Scenario: comment and delete a mobile post
     When I click on selector "a.comment-action.inactive"
@@ -39,9 +37,9 @@ Feature: reactions mobile post
     And I press "Comment"
     Then I should see "is that a poodle?" within ".comment-container"
     When I go to the stream page
-    And I should see "1 reaction" within ".show-comments"
-    And I click on selector "a.show-comments"
+    And I should see "1 comment" within ".show-comments"
     And I should see "1" within ".comment-count"
-    When I click on selector "a.comment-action"
+    When I click on selector "a.show-comments"
+    And I click on selector "a.comment-action"
     And I confirm the alert after I click on selector "a.remove"
-    Then I should not see "1 reaction" within ".show-comments"
+    Then I should see "0 comments" within ".show-comments"
diff --git a/spec/javascripts/mobile/mobile_comments_spec.js b/spec/javascripts/mobile/mobile_comments_spec.js
index 290ba618aa..d2405a4e65 100644
--- a/spec/javascripts/mobile/mobile_comments_spec.js
+++ b/spec/javascripts/mobile/mobile_comments_spec.js
@@ -103,20 +103,20 @@ describe("Diaspora.Mobile.Comments", function(){
     });
 
     it("Increase reaction count from 1", function(){
-      expect(this.toggleReactionsLink.text().trim()).toBe("5 reactions");
+      expect(this.toggleReactionsLink.text().trim()).toBe("5 comments");
       Diaspora.Mobile.Comments.increaseReactionCount(this.bottomBar);
-      expect(this.toggleReactionsLink.text().trim()).toBe("6 reactions");
+      expect(this.toggleReactionsLink.text().trim()).toBe("6 comments");
     });
 
     it("Creates the reaction link when no reactions", function(){
       var parent = this.toggleReactionsLink.parent();
       var postGuid = this.bottomBar.parents(".stream-element").data("guid");
       this.toggleReactionsLink.remove();
-      parent.prepend($("<span/>", {"class": "show-comments"}).text("No reaction"));
+      parent.prepend($("<span/>", {"class": "show-comments"}).text("0 comments"));
 
       Diaspora.Mobile.Comments.increaseReactionCount(this.bottomBar);
       this.toggleReactionsLink = this.bottomBar.find(".show-comments").first();
-      expect(this.toggleReactionsLink.text().trim()).toBe("1 reaction");
+      expect(this.toggleReactionsLink.text().trim()).toBe("1 comment");
       expect(this.toggleReactionsLink.attr("href")).toBe("/posts/" + postGuid + "/comments.mobile");
     });
   });
-- 
GitLab