Comment: don't show downvote summary if we're not showing

This commit is contained in:
Carl Chenet 2017-05-23 14:16:32 +02:00
parent 7855b2c3c4
commit 49dd502de2
2 changed files with 10 additions and 6 deletions

View file

@ -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

View file

@ -100,8 +100,8 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
<span class="reason">
<% 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