Permalink
Browse files

if a comment is downvoted, show the comment's user a summary of its d…

…ownvote reasons
  • Loading branch information...
jcs committed Sep 3, 2012
1 parent 49feb9b commit 5a72a9d6a7cd47cd61f42228ad4b7527b576a497
Showing with 18 additions and 4 deletions.
  1. +10 −0 app/models/comment.rb
  2. +8 −4 app/views/comments/_comment.html.erb
View
@@ -79,6 +79,16 @@ def assign_votes
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?
@@ -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 %>

1 comment on commit 5a72a9d

@skalnik

This comment has been minimized.

Show comment
Hide comment
@skalnik

skalnik commented on 5a72a9d Sep 3, 2012

🤘

Please sign in to comment.