2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-04 02:34:21 +08:00
|
|
|
module Jobs
|
|
|
|
|
2019-10-02 12:01:53 +08:00
|
|
|
class PendingReviewablesReminder < ::Jobs::Scheduled
|
2022-05-05 00:19:43 +08:00
|
|
|
every 15.minutes
|
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
|
2022-05-05 00:19:43 +08:00
|
|
|
.where('latest_score < ?', SiteSetting.notify_about_flags_after.to_f.hours.ago)
|
2019-01-04 01:03:01 +08:00
|
|
|
.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(', @')} " : ""
|
|
|
|
|
2021-12-10 21:17:39 +08:00
|
|
|
message = GroupMessage.new(
|
|
|
|
Group[:moderators].name,
|
|
|
|
'reviewables_reminder',
|
|
|
|
{
|
|
|
|
limit_once_per: false,
|
|
|
|
message_params: { mentions: mentions, count: SiteSetting.notify_about_flags_after }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
Topic.transaction do
|
|
|
|
message.delete_previous!(match_raw: false)
|
|
|
|
@sent_reminder = message.create.present?
|
|
|
|
end
|
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
|
2019-12-03 17:05:53 +08:00
|
|
|
Discourse.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)
|
2019-12-03 17:05:53 +08:00
|
|
|
Discourse.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
|
2020-04-30 14:48:34 +08:00
|
|
|
"last_notified_reviewable_id"
|
2017-04-20 04:16:27 +08:00
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
def self.clear_key
|
2019-12-03 17:05:53 +08:00
|
|
|
Discourse.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-04-20 04:16:27 +08:00
|
|
|
.human_users
|
|
|
|
.order('last_seen_at DESC')
|
|
|
|
.limit(3)
|
|
|
|
.pluck(:username)
|
2014-04-04 02:34:21 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|