mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 05:53:44 +08:00
b9abd7dc9e
This feature can be enabled by choosing a destination for the `shared drafts category` site setting. * Staff members can create shared drafts, choosing a destination category for the topic when it is published. * Shared Drafts can be viewed in their category, or above the topic list for the destination category where it will end up. * When the shared draft is ready, it can be published to the appropriate category by clicking a button on the topic view. * When published, Drafts change their timestamps to the current time, and any edits to the original post are removed.
42 lines
1.0 KiB
Ruby
42 lines
1.0 KiB
Ruby
class TopicPublisher
|
|
|
|
def initialize(topic, published_by, category_id)
|
|
@topic = topic
|
|
@published_by = published_by
|
|
@category_id = category_id
|
|
end
|
|
|
|
def publish!
|
|
TopicTimestampChanger.new(timestamp: Time.zone.now, topic: @topic).change! do
|
|
if @topic.private_message?
|
|
@topic = TopicConverter.new(@topic, @published_by)
|
|
.convert_to_public_topic(@category_id)
|
|
else
|
|
@topic.change_category_to_id(@category_id)
|
|
end
|
|
|
|
@topic.update_columns(visible: true)
|
|
|
|
StaffActionLogger.new(@published_by).log_topic_published(@topic)
|
|
|
|
# Clean up any publishing artifacts
|
|
SharedDraft.where(topic: @topic).delete_all
|
|
TopicTimer.where(topic: @topic).update_all(
|
|
deleted_at: DateTime.now,
|
|
deleted_by_id: @published_by.id
|
|
)
|
|
|
|
op = @topic.first_post
|
|
if op.present?
|
|
op.revisions.delete_all
|
|
op.update_column(:version, 1)
|
|
end
|
|
end
|
|
|
|
MessageBus.publish("/topic/#{@topic.id}", reload_topic: true, refresh_stream: true)
|
|
|
|
@topic
|
|
end
|
|
|
|
end
|