forked from pingcap/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopic_publisher.rb
54 lines (40 loc) · 1.26 KB
/
topic_publisher.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true
class TopicPublisher
def initialize(topic, published_by, category_id)
@topic = topic
@published_by = published_by
@category_id = category_id
end
def publish!
published_at = Time.zone.now
TopicTimestampChanger.new(timestamp: published_at, topic: @topic).change! do
if @topic.private_message?
@topic = TopicConverter.new(@topic, @published_by)
.convert_to_public_topic(@category_id)
else
PostRevisor.new(@topic.first_post, @topic).revise!(@published_by,
category_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_columns(
version: 1,
public_version: 1,
last_version_at: published_at
)
end
end
MessageBus.publish("/topic/#{@topic.id}", reload_topic: true, refresh_stream: true)
@topic
end
end