2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-03 14:34:21 -04:00
|
|
|
module Jobs
|
|
|
|
|
2019-10-02 00:01:53 -04:00
|
|
|
class PendingReviewablesReminder < ::Jobs::Scheduled
|
2017-04-19 16:16:27 -04:00
|
|
|
every 1.hour
|
2014-04-03 14:34:21 -04:00
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
attr_reader :sent_reminder
|
2017-05-22 15:18:13 -04:00
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
def execute(args)
|
|
|
|
@sent_reminder = false
|
2017-05-22 15:18:13 -04:00
|
|
|
|
2019-01-03 12:03:01 -05: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-22 15:18:13 -04:00
|
|
|
usernames = active_moderator_usernames
|
|
|
|
mentions = usernames.size > 0 ? "@#{usernames.join(', @')} " : ""
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
@sent_reminder = PostCreator.create(
|
2017-05-22 15:18:13 -04:00
|
|
|
Discourse.system_user,
|
|
|
|
target_group_names: Group[:moderators].name,
|
|
|
|
archetype: Archetype.private_message,
|
|
|
|
subtype: TopicSubtype.system_message,
|
2019-04-01 14:46:56 -04: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-03 12:03:01 -05:00
|
|
|
).present?
|
2017-05-22 15:18:13 -04:00
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
self.class.last_notified_id = reviewable_ids[0]
|
2017-05-22 15:18:13 -04:00
|
|
|
end
|
|
|
|
end
|
2017-04-19 16:16:27 -04:00
|
|
|
end
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
def self.last_notified_id
|
2019-12-03 04:05:53 -05:00
|
|
|
Discourse.redis.get(last_notified_key).to_i
|
2017-04-19 16:16:27 -04:00
|
|
|
end
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
def self.last_notified_id=(arg)
|
2019-12-03 04:05:53 -05:00
|
|
|
Discourse.redis.set(last_notified_key, arg)
|
2017-04-19 16:16:27 -04:00
|
|
|
end
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
def self.last_notified_key
|
2020-04-30 02:48:34 -04:00
|
|
|
"last_notified_reviewable_id"
|
2017-04-19 16:16:27 -04:00
|
|
|
end
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
def self.clear_key
|
2019-12-03 04:05:53 -05:00
|
|
|
Discourse.redis.del(last_notified_key)
|
2017-04-19 16:16:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def active_moderator_usernames
|
2017-05-22 15:18:13 -04:00
|
|
|
User.where(moderator: true)
|
2017-04-19 16:16:27 -04:00
|
|
|
.human_users
|
|
|
|
.order('last_seen_at DESC')
|
|
|
|
.limit(3)
|
|
|
|
.pluck(:username)
|
2014-04-03 14:34:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|