2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-06-19 03:46:50 +08:00
|
|
|
module Jobs
|
2019-10-02 12:01:53 +08:00
|
|
|
class PendingQueuedPostsReminder < ::Jobs::Scheduled
|
2022-05-05 00:33:43 +08:00
|
|
|
every 15.minutes
|
2015-06-19 03:46:50 +08:00
|
|
|
|
|
|
|
def execute(args)
|
2017-09-13 05:44:31 +08:00
|
|
|
return true unless SiteSetting.notify_about_queued_posts_after > 0
|
2015-06-19 03:46:50 +08:00
|
|
|
|
2017-05-23 04:26:18 +08:00
|
|
|
queued_post_ids = should_notify_ids
|
|
|
|
|
|
|
|
if queued_post_ids.size > 0 && last_notified_id.to_i < queued_post_ids.max
|
2017-09-13 05:44:31 +08:00
|
|
|
PostCreator.create(
|
|
|
|
Discourse.system_user,
|
|
|
|
target_group_names: Group[:moderators].name,
|
|
|
|
archetype: Archetype.private_message,
|
|
|
|
subtype: TopicSubtype.system_message,
|
|
|
|
title:
|
|
|
|
I18n.t(
|
|
|
|
"system_messages.queued_posts_reminder.subject_template",
|
|
|
|
count: queued_post_ids.size,
|
|
|
|
),
|
|
|
|
raw:
|
|
|
|
I18n.t(
|
|
|
|
"system_messages.queued_posts_reminder.text_body_template",
|
|
|
|
base_url: Discourse.base_url,
|
2023-01-09 20:20:10 +08:00
|
|
|
),
|
2017-09-13 05:44:31 +08:00
|
|
|
)
|
|
|
|
|
2017-05-23 04:26:18 +08:00
|
|
|
self.last_notified_id = queued_post_ids.max
|
2015-06-19 03:46:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_notify_ids
|
2021-12-09 01:12:24 +08:00
|
|
|
ReviewableQueuedPost
|
|
|
|
.pending
|
2022-05-05 00:33:43 +08:00
|
|
|
.where("created_at < ?", SiteSetting.notify_about_queued_posts_after.to_f.hours.ago)
|
2019-01-04 01:03:01 +08:00
|
|
|
.pluck(:id)
|
2015-06-19 03:46:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def last_notified_id
|
2019-12-03 17:05:53 +08:00
|
|
|
(i = Discourse.redis.get(self.class.last_notified_key)) && i.to_i
|
2015-06-19 03:46:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def last_notified_id=(arg)
|
2019-12-03 17:05:53 +08:00
|
|
|
Discourse.redis.set(self.class.last_notified_key, arg)
|
2015-06-19 03:46:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.last_notified_key
|
2020-04-30 14:48:34 +08:00
|
|
|
"last_notified_queued_post_id"
|
2015-06-19 03:46:50 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|