diff --git a/app/assets/javascripts/application.js.erb b/app/assets/javascripts/application.js.erb index f83cd03..7d907c5 100644 --- a/app/assets/javascripts/application.js.erb +++ b/app/assets/javascripts/application.js.erb @@ -116,7 +116,12 @@ var _Lobsters = Class.extend({ var li = $(voterEl).closest(".story, .comment"); var scoreDiv = li.find("div.score").get(0); - var score = parseInt(scoreDiv.innerHTML); + var score = 0; + var showScore = true; + if (scoreDiv.innerHTML == "-") + showScore = false; + else + score = parseInt(scoreDiv.innerHTML); var action = ""; if (li.hasClass("upvoted") && point > 0) { @@ -150,7 +155,8 @@ var _Lobsters = Class.extend({ action = "downvote"; } - scoreDiv.innerHTML = score; + if (showScore) + scoreDiv.innerHTML = score; if (action == "upvote" || action == "unvote") { li.find(".reason").html(""); diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 274939f..e6ecc52 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -487,6 +487,10 @@ li div.details { opacity: 0.5; } +.comment.bad { + opacity: 0.7; +} + .comment:target { background-color: #fffcd7; border-radius: 20px; diff --git a/app/models/comment.rb b/app/models/comment.rb index 49c4cd2..0308875 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -32,6 +32,8 @@ class Comment < ActiveRecord::Base # after this many minutes old, a comment cannot be edited MAX_EDIT_MINS = (60 * 6) + SCORE_RANGE_TO_HIDE = (-2 .. 4) + validate do self.comment.to_s.strip == "" && errors.add(" ", I18n.t( 'models.comment.commentcannotbeblank')) @@ -429,6 +431,16 @@ 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) + score + else + "-" + end + end + def short_id_url Rails.application.root_url + "c/#{self.short_id}" end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index e5957a7..6b47be9 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -5,9 +5,7 @@ data-shortid="<%= comment.short_id if comment.persisted? %>" class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ? "upvoted" : "downvoted") : "" %> - <%= comment.score <= -1 ? "negative_1" : "" %> - <%= comment.score <= -3 ? "negative_3" : "" %> - <%= comment.score <= -5 ? "negative_5" : "" %>"> + <%= comment.score < Comment::SCORE_RANGE_TO_HIDE.first ? "bad" : "" %>"> <% if !comment.is_gone? %>
<% if @user %> @@ -15,7 +13,7 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ? <% else %> <%= link_to "", login_path, :class => "upvoter" %> <% end %> -
<%= comment.score %>
+
<%= comment.score_for_user(@user) %>
<% if @user && @user.can_downvote?(comment) %> <% else %>