Use better method for querying moderation reports on posts and topics

- Also moved the control logic out of the views and into the models
This commit is contained in:
BrokenEagle
2020-01-19 20:14:42 +00:00
parent 16100ecfe6
commit 29e8b89c93
8 changed files with 16 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
$("#threshold-comments-notice-for-<%= @post.id %>").hide();
var current_comment_section = $("div.comments-for-post[data-post-id=<%= @post.id %>] div.list-of-comments");
current_comment_section.html("<%= j(render(partial: 'comments/partials/show/comment', collection: @comments, locals: { context: :index_for_post, dtext_data: DText.preprocess(@comments.map(&:body)), moderation_reports: (CurrentUser.is_moderator? ? @post.moderation_reports : []) })) %>");
current_comment_section.html("<%= j(render(partial: 'comments/partials/show/comment', collection: @comments, locals: { context: :index_for_post, dtext_data: DText.preprocess(@comments.map(&:body)), moderation_reports: @post.viewable_moderation_reports })) %>");
$(window).trigger("danbooru:index_for_post", [<%= @post.id %>]);

View File

@@ -3,7 +3,7 @@
<%= render "comments/partials/index/header", :post => post %>
<% end %>
<% if CurrentUser.is_moderator? && post.moderation_reports.present? %>
<% if post.viewable_moderation_reports.present? %>
<div class="row moderation-comments-notice">
<span class="info" id="moderation-comments-notice-for-<%= post.id %>">
This post has comments reported for moderation! (<%= post.moderation_reports.length %> <%= (post.moderation_reports.length == 1 ? "report" : "reports") %>)
@@ -20,7 +20,7 @@
<div class="list-of-comments list-of-messages">
<% if comments.present? %>
<%= render partial: "comments/partials/show/comment", collection: comments, locals: { context: :index_by_post, dtext_data: DText.preprocess(comments.map(&:body)), moderation_reports: (CurrentUser.is_moderator? ? post.moderation_reports : []) } %>
<%= render partial: "comments/partials/show/comment", collection: comments, locals: { context: :index_by_post, dtext_data: DText.preprocess(comments.map(&:body)), moderation_reports: post.viewable_moderation_reports } %>
<% elsif post.last_commented_at.present? %>
<p>There are no visible comments.</p>
<% else %>

View File

@@ -4,7 +4,7 @@
<%- # moderation_reports %>
<div class="list-of-forum-posts list-of-messages">
<% if CurrentUser.is_moderator? && moderation_reports.present? %>
<% if moderation_reports.present? %>
<div class="row moderation-forums-notice">
<span class="info" id="moderation-forums-notice-for-topic">
This topic has forum posts reported for moderation! (<%= moderation_reports.length %> <%= (moderation_reports.length == 1 ? "report" : "reports") %>)

View File

@@ -20,7 +20,7 @@
</div>
<% end %>
<%= render "forum_posts/listing", forum_posts: @forum_posts, original_forum_post_id: @forum_topic.original_post.id, dtext_data: DText.preprocess(@forum_posts.map(&:body)), moderation_reports: (CurrentUser.is_moderator? ? @forum_topic.moderation_reports : []) %>
<%= render "forum_posts/listing", forum_posts: @forum_posts, original_forum_post_id: @forum_topic.original_post.id, dtext_data: DText.preprocess(@forum_posts.map(&:body)), moderation_reports: @forum_topic.viewable_moderation_reports %>
<% if CurrentUser.is_member? %>
<% if CurrentUser.is_moderator? || !@forum_topic.is_locked? %>

View File

@@ -2,7 +2,7 @@
<div id="a-show">
<h1><%= link_to_user @user %></h1>
<% if !@user.is_moderator? && CurrentUser.is_moderator? && @user.moderation_reports.present? %>
<% if @user.viewable_moderation_reports.present? %>
<div class="moderation-users-notice">
<span class="info" id="moderation-users-notice-for-<%= @user.id %>">
This user has been reported for moderation! (<%= @user.moderation_reports.length %> <%= (@user.moderation_reports.length == 1 ? "report" : "reports") %>)