From 0cf592af7133bd38a0b27628a65c8b9a321cc893 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 30 Oct 2015 20:06:36 +0100 Subject: [PATCH] Fixes two issues in comment_tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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” --- app/models/comment.rb | 2 ++ lib/comment_tree.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 9805b55f9..bea03a65a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/lib/comment_tree.rb b/lib/comment_tree.rb index 818a02006..8d0e072dd 100644 --- a/lib/comment_tree.rb +++ b/lib/comment_tree.rb @@ -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