2014-04-03 14:34:21 -04:00
|
|
|
require_dependency 'email/message_builder'
|
|
|
|
require_dependency 'flag_query'
|
|
|
|
|
|
|
|
class PendingFlagsMailer < ActionMailer::Base
|
|
|
|
include Email::BuildEmailHelper
|
|
|
|
|
|
|
|
def notify
|
|
|
|
return unless SiteSetting.contact_email
|
|
|
|
|
2014-09-23 12:37:31 -04:00
|
|
|
@posts, @topics, @users = FlagQuery.flagged_posts_report(Discourse.system_user, 'active', 0, 20)
|
2014-04-03 14:34:21 -04:00
|
|
|
|
|
|
|
@posts.each do |post| # Note: post is a Hash, not a Post.
|
2014-09-23 12:37:31 -04:00
|
|
|
topic = @topics.select { |t| t[:id] == post[:topic_id] }.first
|
|
|
|
|
|
|
|
post[:title] = topic[:title]
|
|
|
|
post[:url] = "#{Discourse.base_url}#{Post.url(topic[:slug], topic[:id], post[:post_number])}"
|
|
|
|
post[:user] = @users.select { |u| u[:id] == post[:user_id] }.first
|
|
|
|
|
2014-04-03 14:34:21 -04:00
|
|
|
counts = flag_reason_counts(post)
|
2014-09-23 12:37:31 -04:00
|
|
|
post[:reason_counts] = counts.map { |reason, count| "#{I18n.t('post_action_types.' + reason.to_s + '.title')}: #{count}" }.join(', ')
|
|
|
|
post[:html_reason_counts] = counts.map { |reason, count| "<strong>#{I18n.t('post_action_types.' + reason.to_s + '.title')}:</strong> #{count}" }.join(', ')
|
2014-04-03 14:34:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@hours = SiteSetting.notify_about_flags_after
|
|
|
|
|
2014-09-23 12:37:31 -04:00
|
|
|
subject = "[#{SiteSetting.title}] " + I18n.t('flags_reminder.subject_template', { count: PostAction.flagged_posts_count })
|
|
|
|
build_email(SiteSetting.contact_email, subject: subject)
|
2014-04-03 14:34:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def flag_reason_counts(post)
|
2014-09-23 12:37:31 -04:00
|
|
|
post[:post_actions].inject({}) do |h,v|
|
|
|
|
h[v[:name_key]] ||= 0
|
|
|
|
h[v[:name_key]] += 1
|
|
|
|
h
|
|
|
|
end
|
2014-04-03 14:34:21 -04:00
|
|
|
end
|
|
|
|
end
|