discourse/app/jobs/regular/toggle_topic_closed.rb

23 lines
549 B
Ruby
Raw Normal View History

module Jobs
class ToggleTopicClosed < Jobs::Base
def execute(args)
topic_timer = TopicTimer.find_by(id: args[:topic_timer_id] || args[:topic_status_update_id])
state = !!args[:state]
if topic_timer.blank? ||
topic_timer.execute_at > Time.zone.now ||
(topic = topic_timer.topic).blank? ||
topic.closed == state
return
end
user = topic_timer.user
if Guardian.new(user).can_close?(topic)
topic.update_status('autoclosed', state, user)
end
end
end
end