Added highlighting and notices for moderators

- Posts and topics have an added moderation_reports function
-- This is so all moderation reports can be loaded in a single query
- Those moderation reports are passed into the render functions separately
-- This is so the individual comments/posts don't have to be queried
This commit is contained in:
BrokenEagle
2020-01-18 21:10:50 +00:00
parent 4cef0e45c2
commit a3e889bdf5
13 changed files with 76 additions and 7 deletions

View File

@@ -181,4 +181,9 @@ class ForumTopic < ApplicationRecord
def update_orignal_post
original_post&.update_columns(:updater_id => CurrentUser.id, :updated_at => Time.now)
end
def moderation_reports
posts_with_reports = posts.joins(:moderation_reports).includes(:moderation_reports).distinct
posts_with_reports.reduce([]) {|arr,post| arr + post.moderation_reports}
end
end

View File

@@ -1811,4 +1811,11 @@ class Post < ApplicationRecord
save
end
def moderation_reports
@moderation_reports ||= begin
comments_with_reports = comments.joins(:moderation_reports).includes(:moderation_reports).distinct
comments_with_reports.reduce([]) {|arr,comment| arr + comment.moderation_reports}
end
end
end