Fixes two issues in comment_tree

* The descendants list for a comment was not being built correctly
* The root comments must be ordered “newest first”, but their
descendants must be ordered “newest last”
This commit is contained in:
kikito
2015-10-30 20:06:36 +01:00
parent 60b3c65b05
commit 0cf592af71
2 changed files with 3 additions and 1 deletions

View File

@@ -23,7 +23,9 @@ class Comment < ActiveRecord::Base
scope :with_visible_author, -> { joins(:user).where("users.hidden_at IS NULL") }
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :sort_by_confidence_score , -> { order(confidence_score: :desc, created_at: :desc) }
scope :sort_descendants_by_confidence_score , -> { order(confidence_score: :desc, created_at: :asc) }
scope :sort_by_created_at, -> { order(created_at: :desc) }
scope :sort_descendants_by_created_at, -> { order(created_at: :asc) }
after_create :call_after_commented

View File

@@ -8,7 +8,7 @@ class CommentTree
@root_comments = commentable.comments.roots.send("sort_by_#{order}").page(page).per(ROOT_COMMENTS_PER_PAGE).for_render
root_descendants = @root_comments.each_with_object([]) do |root, col|
col += Comment.descendants_of(root).send("sort_by_#{order}").for_render.to_a
col.concat(Comment.descendants_of(root).send("sort_descendants_by_#{order}").for_render.to_a)
end
@comments = root_comments + root_descendants