Hide super low score comments if they are child comments (#20612)
This commit is contained in:
parent
05f75c396e
commit
e5064b418f
4 changed files with 19 additions and 11 deletions
|
|
@ -94,12 +94,14 @@ module CommentsHelper
|
|||
private
|
||||
|
||||
def nested_comments(tree:, commentable:, is_view_root: false)
|
||||
comments = tree.map do |comment, sub_comments|
|
||||
render("comments/comment", comment: comment, commentable: commentable,
|
||||
is_view_root: is_view_root, is_childless: sub_comments.empty?,
|
||||
subtree_html: nested_comments(tree: sub_comments, commentable: commentable))
|
||||
comments = tree.filter_map do |comment, sub_comments|
|
||||
is_childless = sub_comments.empty?
|
||||
unless comment.decorate.super_low_quality && is_childless
|
||||
render("comments/comment", comment: comment, commentable: commentable,
|
||||
is_view_root: is_view_root, is_childless: is_childless,
|
||||
subtree_html: nested_comments(tree: sub_comments, commentable: commentable))
|
||||
end
|
||||
end
|
||||
|
||||
safe_join(comments)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,2 @@
|
|||
<% comment, sub_comments = comment_node %>
|
||||
<% unless comment.decorate.super_low_quality && sub_comments.empty? %>
|
||||
<%= nested_comments(tree: { comment => sub_comments }, commentable: @article, is_view_root: true) %>
|
||||
<% end %>
|
||||
<%= nested_comments(tree: { comment => sub_comments }, commentable: @article, is_view_root: true) %>
|
||||
|
|
|
|||
|
|
@ -144,9 +144,7 @@
|
|||
<% else %>
|
||||
<% Comments::Tree.for_commentable(@commentable, include_negative: user_signed_in?).each do |comment, sub_comments| %>
|
||||
<% cache ["comment_root_#{user_signed_in?}", comment] do %>
|
||||
<% unless comment.decorate.super_low_quality && sub_comments.empty? %>
|
||||
<%= nested_comments(tree: { comment => sub_comments }, commentable: @commentable, is_view_root: true) %>
|
||||
<% end %>
|
||||
<%= nested_comments(tree: { comment => sub_comments }, commentable: @commentable, is_view_root: true) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -80,6 +80,16 @@ RSpec.describe "Comments" do
|
|||
end
|
||||
end
|
||||
|
||||
context "when there are child spam comments" do
|
||||
it "hides child spam comment if it has no children" do
|
||||
create(:comment, commentable: article, score: -500, body_markdown: "child-spam-comment", parent: comment)
|
||||
sign_in user
|
||||
get "#{article.path}/comments"
|
||||
expect(response.body).not_to include("child-spam-comment")
|
||||
expect(response.body).not_to include("Comment deleted")
|
||||
end
|
||||
end
|
||||
|
||||
context "when the comment is a root" do
|
||||
it "displays the comment hidden message if the comment is hidden" do
|
||||
comment.update(hidden_by_commentable_user: true)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue