mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 10:15:48 +08:00
6d72c8ab19
This PR revamps the topic timer UI, using the time shortcut selector from the bookmark modal. * Fixes an issue where the duration of hours/days after last reply or auto delete replies was not enforced to be > 0 * Fixed an issue where the timer dropdown options were not reloaded correctly if the topic status changes in the background (use `MessageBus` to publish topic state in the open/close timer jobs) * Moved the duration input and the "based on last post" option from the `future-date-input` component, as it was only used for topic timers. Also moved out the notice that is displayed which was also only relevant for topic timers.
32 lines
789 B
Ruby
32 lines
789 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class CloseTopic < ::Jobs::TopicTimerBase
|
|
def execute_timer_action(topic_timer, topic)
|
|
silent = @args[:silent]
|
|
user = topic_timer.user
|
|
|
|
if topic.closed?
|
|
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
|
|
|
|
# this handles deleting the topic timer as wel, see TopicStatusUpdater
|
|
topic.update_status('autoclosed', true, user, { silent: silent })
|
|
|
|
MessageBus.publish("/topic/#{topic.id}", reload_topic: true)
|
|
end
|
|
end
|
|
end
|