diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 525586f18..9eb27226b 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -16,11 +16,8 @@ module CommentableActions def show set_resource_votes(resource) @commentable = resource - @root_comments = resource.comments.roots.send("sort_by_#{@current_order}").page(params[:page]).per(10).for_render - @comments = @root_comments.inject([]){|all, root| all + Comment.descendants_of(root).for_render} - @all_visible_comments = @root_comments + @comments - - set_comment_flags(@all_visible_comments) + @comment_tree = CommentTree.new(@commentable, params[:page], @current_order) + set_comment_flags(@comment_tree.comments) set_resource_instance end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 7fef232c5..9ac29e4da 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -12,14 +12,9 @@ module CommentsHelper parent_id.blank? ? dom_id(commentable) : "comment_#{parent_id}" end - def select_children(comments, parent) - return [] if comments.blank? - comments.select{|c| c.parent_id == parent.id} - end - - def count_children(comments, parent) - return 0 if comments.blank? - comments.count{ |c| c.parent_id == parent.id } + def child_comments_of(parent) + return [] unless @comment_tree + @comment_tree.children_of(parent) end def user_level_class(comment) diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index ac54238a0..1ec571633 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -3,7 +3,7 @@
<%= t("comments.comment.deleted") %>