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
|
2022-05-04 12:19:43 -04:00
|
|
|
every 15.minutes
|
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
|
2022-05-04 12:19:43 -04:00
|
|
|
.where('latest_score < ?', SiteSetting.notify_about_flags_after.to_f.hours.ago)
|
2019-01-03 12:03:01 -05:00
|
|
|
.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(', @')} " : ""
|
|
|
|
|
2021-12-10 08:17:39 -05: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-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
|