2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-04 02:34:21 +08:00
|
|
|
require_dependency 'flag_query'
|
|
|
|
|
|
|
|
module Jobs
|
|
|
|
|
2019-04-02 02:46:56 +08:00
|
|
|
class PendingReviewablesReminder < 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-04-02 02:46:56 +08:00
|
|
|
title: I18n.t('reviewables_reminder.subject_template', count: reviewable_ids.size),
|
|
|
|
raw: mentions + I18n.t('reviewables_reminder.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
|