Comment: cap downvotes to -5, only collapse when it reaches

This commit is contained in:
Carl Chenet 2017-05-11 12:37:38 +02:00
parent 05743959cf
commit e8d11e28d7
5 changed files with 13 additions and 10 deletions

View file

@ -476,10 +476,10 @@ li div.details {
opacity: 0.7;
}
.negative_3 {
opacity: 0.5;
opacity: 0.6;
}
.negative_5 {
opacity: 0.2;
opacity: 0.5;
}
.comment.highlighted {

View file

@ -26,6 +26,9 @@ class Comment < ActiveRecord::Base
DOWNVOTABLE_DAYS = 7
# the lowest a score can go, which makes it collapsed by default
DOWNVOTABLE_MIN_SCORE = -5
# after this many minutes old, a comment cannot be edited
MAX_EDIT_MINS = (60 * 6)
@ -321,7 +324,7 @@ class Comment < ActiveRecord::Base
end
def is_downvotable?
if self.created_at
if self.created_at && self.score >= DOWNVOTABLE_MIN_SCORE
Time.now - self.created_at <= DOWNVOTABLE_DAYS.days
else
false

View file

@ -341,8 +341,7 @@ class Story < ActiveRecord::Base
end
def is_downvotable?
return true
if self.created_at
if self.created_at && self.score >= -5
Time.now - self.created_at <= DOWNVOTABLE_DAYS.days
else
false

View file

@ -65,7 +65,7 @@ class User < ActiveRecord::Base
MIN_KARMA_TO_SUGGEST = 10
# minimum karma required to be able to downvote comments
MIN_KARMA_TO_DOWNVOTE = 100
MIN_KARMA_TO_DOWNVOTE = 50
# minimum karma required to be able to submit new stories
MIN_KARMA_TO_SUBMIT_STORIES = -4
@ -176,7 +176,7 @@ class User < ActiveRecord::Base
# user can unvote
return true
end
elsif obj.is_a?(Comment)
elsif obj.is_a?(Comment) && obj.is_downvotable?
return !self.is_new? && (self.karma >= MIN_KARMA_TO_DOWNVOTE)
end

View file

@ -1,13 +1,14 @@
<input id="comment_folder_<%= comment.short_id %>"
class="comment_folder_button" type="checkbox"
<%= comment.score <= -1 ? "checked" : "" %>>
<%= comment.score <= Comment::DOWNVOTABLE_MIN_SCORE ? "checked" : "" %>>
<div id="comment_<%= comment.short_id %>"
data-shortid="<%= comment.short_id if comment.persisted? %>"
class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
"upvoted" : "downvoted") : "" %>
<%= comment.highlighted ? "highlighted" : "" %>
<%= comment.score <= 0 ? "negative" : "" %>
<%= comment.score <= -1 ? "negative_1" : "" %>">
<%= comment.score <= -1 ? "negative_1" : "" %>
<%= comment.score <= -3 ? "negative_3" : "" %>
<%= comment.score <= -5 ? "negative_5" : "" %>">
<% if !comment.is_gone? %>
<div class="voters">
<% if @user %>