docbrown/app/queries/comments/tree.rb
Anna Buianova 7125a62db0
Changed logic for hiding and displaying low-quality marker for comments based on their score (#20581)
* Specs for revised comments thresholds

* Changed thresholds for low quality comments

* Added specs for comments page

* Fixed /comments and related specs

* Reorganized code for comments trees

* Specs for podcasts episodes comments

* Refactored Comments::Tree

* Refactored Comments::Tree + added specs

* Made build_sort_query private
2024-02-05 09:27:24 -05:00

34 lines
969 B
Ruby

module Comments
module Tree
module_function
def for_commentable(commentable, limit: 0, order: nil, include_negative: false)
collection = commentable.comments
.includes(user: %i[setting profile])
.arrange(order: build_sort_query(order))
.to_a[0..limit - 1]
.to_h
collection.reject! { |comment| comment.score.negative? } unless include_negative
collection
end
def for_root_comment(root_comment, include_negative: false)
sub_comments = root_comment.subtree.includes(user: %i[setting profile]).arrange[root_comment]
sub_comments.reject! { |comment| comment.score.negative? } unless include_negative
{ root_comment => sub_comments }
end
def build_sort_query(order)
case order
when "latest"
"created_at DESC"
when "oldest"
"created_at ASC"
else
"score DESC"
end
end
private_class_method :build_sort_query
end
end