mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FEATURE: View flags grouped by topic
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
require 'ostruct'
|
||||
|
||||
module FlagQuery
|
||||
|
||||
def self.flagged_posts_report(current_user, filter, offset = 0, per_page = 25)
|
||||
@ -128,6 +130,44 @@ module FlagQuery
|
||||
|
||||
end
|
||||
|
||||
def self.flagged_topics
|
||||
|
||||
results = PostAction
|
||||
.flags
|
||||
.active
|
||||
.includes(post: [:user, :topic])
|
||||
.order('post_actions.created_at DESC')
|
||||
|
||||
ft_by_id = {}
|
||||
users_by_id = {}
|
||||
topics_by_id = {}
|
||||
|
||||
results.each do |pa|
|
||||
if pa.post.present? && pa.post.topic.present?
|
||||
ft = ft_by_id[pa.post.topic.id] ||= OpenStruct.new(
|
||||
topic: pa.post.topic,
|
||||
flag_counts: {},
|
||||
user_ids: [],
|
||||
last_flag_at: pa.created_at
|
||||
)
|
||||
|
||||
topics_by_id[pa.post.topic.id] = pa.post.topic
|
||||
|
||||
ft.flag_counts[pa.post_action_type_id] ||= 0
|
||||
ft.flag_counts[pa.post_action_type_id] += 1
|
||||
|
||||
ft.user_ids << pa.post.user_id
|
||||
ft.user_ids.uniq!
|
||||
|
||||
users_by_id[pa.post.user_id] ||= pa.post.user
|
||||
end
|
||||
end
|
||||
|
||||
Topic.preload_custom_fields(topics_by_id.values, TopicList.preloaded_custom_fields)
|
||||
|
||||
{ flagged_topics: ft_by_id.values, users: users_by_id.values }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.excerpt(cooked)
|
||||
|
Reference in New Issue
Block a user