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