2020-03-19 11:36:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
2021-01-18 22:30:58 -05:00
|
|
|
class DeleteReplies < ::Jobs::TopicTimerBase
|
|
|
|
def execute_timer_action(topic_timer, topic)
|
2020-03-19 11:36:31 -04:00
|
|
|
unless Guardian.new(topic_timer.user).is_staff?
|
|
|
|
topic_timer.trash!(Discourse.system_user)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
replies = topic.posts.where("posts.post_number > 1")
|
2020-12-23 00:30:10 -05:00
|
|
|
replies = replies.where("like_count < ?", SiteSetting.skip_auto_delete_reply_likes) if SiteSetting.skip_auto_delete_reply_likes > 0
|
|
|
|
|
2021-02-04 19:12:56 -05:00
|
|
|
replies.where('posts.created_at < ?', topic_timer.duration_minutes.minutes.ago).each do |post|
|
2020-03-19 11:36:31 -04:00
|
|
|
PostDestroyer.new(topic_timer.user, post, context: I18n.t("topic_statuses.auto_deleted_by_timer")).destroy
|
|
|
|
end
|
|
|
|
|
2021-02-04 19:12:56 -05:00
|
|
|
topic_timer.execute_at = (replies.minimum(:created_at) || Time.zone.now) + topic_timer.duration_minutes.minutes
|
2020-03-19 11:36:31 -04:00
|
|
|
topic_timer.save
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|