From e8d11e28d733d4f2cd69ee321d0b3da519ccffc3 Mon Sep 17 00:00:00 2001 From: Carl Chenet Date: Thu, 11 May 2017 12:37:38 +0200 Subject: [PATCH] Comment: cap downvotes to -5, only collapse when it reaches --- app/assets/stylesheets/application.css | 4 ++-- app/models/comment.rb | 5 ++++- app/models/story.rb | 3 +-- app/models/user.rb | 4 ++-- app/views/comments/_comment.html.erb | 7 ++++--- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 0b0868d..46f162b 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -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 { diff --git a/app/models/comment.rb b/app/models/comment.rb index 92f646f..a1eec60 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/story.rb b/app/models/story.rb index edfc999..3a85cf7 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 6fc1a4d..1aa8c02 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 49937f7..ee3aee1 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,13 +1,14 @@ > + <%= comment.score <= Comment::DOWNVOTABLE_MIN_SCORE ? "checked" : "" %>>
<%= 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? %>
<% if @user %>