2014-04-04 02:34:21 +08:00
|
|
|
require_dependency 'flag_query'
|
|
|
|
|
|
|
|
module Jobs
|
|
|
|
|
|
|
|
class PendingFlagsReminder < Jobs::Scheduled
|
2017-04-20 04:16:27 +08:00
|
|
|
every 1.hour
|
2014-04-04 02:34:21 +08:00
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
attr_reader :sent_reminder
|
2017-05-23 03:18:13 +08:00
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
def execute(args)
|
|
|
|
@sent_reminder = false
|
2017-05-23 03:18:13 +08:00
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
if SiteSetting.notify_about_flags_after > 0
|
|
|
|
reviewable_ids = Reviewable
|
|
|
|
.pending
|
|
|
|
.default_visible
|
|
|
|
.where('latest_score < ?', SiteSetting.notify_about_flags_after.to_i.hours.ago)
|
|
|
|
.order('id DESC')
|
|
|
|
.pluck(:id)
|
|
|
|
|
|
|
|
if reviewable_ids.size > 0 && self.class.last_notified_id < reviewable_ids[0]
|
2017-05-23 03:18:13 +08:00
|
|
|
usernames = active_moderator_usernames
|
|
|
|
mentions = usernames.size > 0 ? "@#{usernames.join(', @')} " : ""
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
@sent_reminder = PostCreator.create(
|
2017-05-23 03:18:13 +08:00
|
|
|
Discourse.system_user,
|
|
|
|
target_group_names: Group[:moderators].name,
|
|
|
|
archetype: Archetype.private_message,
|
|
|
|
subtype: TopicSubtype.system_message,
|
2019-01-04 01:03:01 +08:00
|
|
|
title: I18n.t('flags_reminder.subject_template', count: reviewable_ids.size),
|
2018-11-08 00:59:42 +08:00
|
|
|
raw: mentions + I18n.t('flags_reminder.flags_were_submitted', count: SiteSetting.notify_about_flags_after, base_path: Discourse.base_path)
|
2019-01-04 01:03:01 +08:00
|
|
|
).present?
|
2017-05-23 03:18:13 +08:00
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
self.class.last_notified_id = reviewable_ids[0]
|
2017-05-23 03:18:13 +08:00
|
|
|
end
|
|
|
|
end
|
2017-04-20 04:16:27 +08:00
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
def self.last_notified_id
|
|
|
|
$redis.get(last_notified_key).to_i
|
2017-04-20 04:16:27 +08:00
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
def self.last_notified_id=(arg)
|
|
|
|
$redis.set(last_notified_key, arg)
|
2017-04-20 04:16:27 +08:00
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
def self.last_notified_key
|
|
|
|
"last_notified_reviewable_id".freeze
|
2017-04-20 04:16:27 +08:00
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
def self.clear_key
|
|
|
|
$redis.del(last_notified_key)
|
2017-04-20 04:16:27 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def active_moderator_usernames
|
2017-05-23 03:18:13 +08:00
|
|
|
User.where(moderator: true)
|
2017-07-28 09:20:09 +08:00
|
|
|
.human_users
|
|
|
|
.order('last_seen_at DESC')
|
|
|
|
.limit(3)
|
|
|
|
.pluck(:username)
|
2014-04-04 02:34:21 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|