if a comment is downvoted, show the comment's user a summary of its downvote reasons

This commit is contained in:
joshua stein 2012-09-03 12:42:32 -05:00
parent 49feb9ba43
commit 5a72a9d6a7
2 changed files with 18 additions and 4 deletions

View File

@ -79,6 +79,16 @@ class Comment < ActiveRecord::Base
self.story.update_comment_count!
end
def downvote_summary
reasons = {}
Vote.where(:comment_id => self.id).each do |v|
reasons[v.reason] ||= 0
reasons[v.reason] += 1
end
reasons.map{|r,v| "#{Vote::COMMENT_REASONS[r]} (#{v})" }.join(", ")
end
def is_gone?
is_deleted?

View File

@ -29,10 +29,14 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
<%= time_ago_in_words(comment.has_been_edited?? comment.updated_at :
comment.created_at).gsub(/^about /, "") %> ago
<span class="reason"><%= comment.current_vote &&
comment.current_vote[:vote] == -1 ?
"(#{Vote::COMMENT_REASONS[comment.current_vote[:reason]].downcase})" :
"" %></span>
<span class="reason">
<% if comment.downvotes > 0 && comment.user_id == @user.try(:id) %>
(<%= comment.downvote_summary.downcase %>)
<% elsif comment.current_vote && comment.current_vote[:vote] == -1 %>
(<%= Vote::COMMENT_REASONS[comment.current_vote[:reason]].downcase
%>)
<% end %>
</span>
<% end %>
<% if !comment.previewing %>