Fix #3351: Mod+: Treat deleted comments as below score threshold.
Comments have three states: visible, hidden, and invisible. Visible comments are always shown. Hidden comments are not shown until the user clicks 'Show all comments'. Invisible comments are never shown to the user. Deleted comments are treated as hidden for moderators and invisible for normal users. Thresholded comments are treated as hidden for all users.
This commit is contained in:
@@ -26,7 +26,7 @@ class PostsController < ApplicationController
|
||||
@comments = @post.comments
|
||||
@comments = @comments.includes(:creator)
|
||||
@comments = @comments.includes(:votes) if CurrentUser.is_member?
|
||||
@comments = @comments.select { |c| c.visible_by?(CurrentUser.user) }
|
||||
@comments = @comments.visible(CurrentUser.user)
|
||||
|
||||
include_deleted = @post.is_deleted? || (@post.parent_id.present? && @post.parent.is_deleted?) || CurrentUser.user.show_deleted_children?
|
||||
@parent_post_set = PostSets::PostRelationship.new(@post.parent_id, :include_deleted => include_deleted)
|
||||
|
||||
@@ -130,10 +130,19 @@ class Comment < ApplicationRecord
|
||||
user.id.in?(votes.map(&:user_id))
|
||||
end
|
||||
|
||||
def visible_by?(user, show_thresholded: false, show_deleted: false)
|
||||
return false if is_deleted? && !show_deleted && !user.is_moderator?
|
||||
return false if score < user.comment_threshold && !is_sticky? && !show_thresholded
|
||||
true
|
||||
def visibility(user)
|
||||
return :invisible if is_deleted? && !user.is_moderator?
|
||||
return :hidden if is_deleted? && user.is_moderator?
|
||||
return :hidden if score < user.comment_threshold && !is_sticky?
|
||||
return :visible
|
||||
end
|
||||
|
||||
def self.hidden(user)
|
||||
select { |comment| comment.visibility(user) == :hidden }
|
||||
end
|
||||
|
||||
def self.visible(user)
|
||||
select { |comment| comment.visibility(user) == :visible }
|
||||
end
|
||||
|
||||
def hidden_attributes
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
<% end %>
|
||||
|
||||
<% @posts.select(&:visible?).each do |post| %>
|
||||
<% if post.comments.any? { |c| c.visible_by?(CurrentUser.user, show_thresholded: true) } %>
|
||||
<% if post.comments.visible(CurrentUser.user).any? || post.comments.hidden(CurrentUser.user).any? %>
|
||||
<%= content_tag(:div, { id: "post_#{post.id}", class: ["post", *PostPresenter.preview_class(post)].join(" ") }.merge(PostPresenter.data_attributes(post))) do %>
|
||||
<div class="preview">
|
||||
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %>
|
||||
</div>
|
||||
<%= render "comments/partials/index/list", post: post, comments: post.comments.select { |c| c.visible_by?(CurrentUser.user) }.last(6), page: :comments %>
|
||||
<%= render "comments/partials/index/list", post: post, comments: post.comments.visible(CurrentUser.user).last(6), page: :comments %>
|
||||
<div class="clearfix"></div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<% end %>
|
||||
|
||||
<div class="row notices">
|
||||
<% if post.comments.any? { |c| !c.visible_by?(CurrentUser.user, show_deleted: true) } || (page == :comments && post.comments.size > 6) %>
|
||||
<% if post.comments.hidden(CurrentUser.user).any? || (page == :comments && post.comments.size > 6) %>
|
||||
<span class="info" id="threshold-comments-notice-for-<%= post.id %>">
|
||||
<%= link_to "Show all comments", comments_path(post_id: post.id), id: "show-all-comments-link", remote: true %>
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user