2021-01-13 06:49:29 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
2021-01-19 11:30:58 +08:00
|
|
|
class CloseTopic < ::Jobs::TopicTimerBase
|
|
|
|
def execute_timer_action(topic_timer, topic)
|
|
|
|
silent = @args[:silent]
|
2021-01-13 06:49:29 +08:00
|
|
|
user = topic_timer.user
|
|
|
|
|
2021-01-19 11:30:58 +08:00
|
|
|
if topic.closed?
|
2021-01-13 06:49:29 +08:00
|
|
|
topic_timer.destroy!
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if !Guardian.new(user).can_close_topic?(topic)
|
|
|
|
topic_timer.destroy!
|
|
|
|
topic.reload
|
|
|
|
|
|
|
|
if topic_timer.based_on_last_post
|
|
|
|
topic.inherit_auto_close_from_category(timer_type: silent ? :silent_close : :close)
|
|
|
|
end
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2021-05-21 09:43:47 +08:00
|
|
|
# this handles deleting the topic timer as well, see TopicStatusUpdater
|
2021-01-13 06:49:29 +08:00
|
|
|
topic.update_status("autoclosed", true, user, { silent: silent })
|
2021-02-03 08:13:32 +08:00
|
|
|
|
|
|
|
MessageBus.publish("/topic/#{topic.id}", reload_topic: true)
|
2021-01-13 06:49:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|