From 49dd502de2bd969515a90646443a3c29b259a1eb Mon Sep 17 00:00:00 2001 From: Carl Chenet Date: Tue, 23 May 2017 14:16:32 +0200 Subject: [PATCH] Comment: don't show downvote summary if we're not showing --- app/models/comment.rb | 12 ++++++++---- app/views/comments/_comment.html.erb | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 0308875..90fc4f8 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -431,10 +431,8 @@ class Comment < ActiveRecord::Base self.upvotes - self.downvotes end - def score_for_user(user) - if (user && user.is_moderator?) || - (self.created_at && self.created_at < 24.hours.ago) || - !SCORE_RANGE_TO_HIDE.include?(score) + def score_for_user(u) + if self.showing_downvotes_for_user?(u) score else "-" @@ -445,6 +443,12 @@ class Comment < ActiveRecord::Base Rails.application.root_url + "c/#{self.short_id}" end + def showing_downvotes_for_user?(u) + return (u && u.is_moderator?) || + (self.created_at && self.created_at < 36.hours.ago) || + !SCORE_RANGE_TO_HIDE.include?(self.score) + end + def to_param self.short_id end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 6b47be9..bd506ff 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -100,8 +100,8 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ? <% if comment.downvotes > 0 && - ((comment.score <= 0 && comment.user_id == @user.try(:id)) || - @user.try("is_moderator?")) %> + comment.showing_downvotes_for_user?(@user) && + (comment.user_id == @user.try(:id) || @user.try("is_moderator?")) %> | <%= comment.vote_summary_for_user(@user).downcase %> <% elsif comment.current_vote && comment.current_vote[:vote] == -1 %> | -1