mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08:00
Add a DiscourseEvent
for when a topic is closed
This commit is contained in:
parent
3e13becf33
commit
7578d8fc44
2 changed files with 18 additions and 0 deletions
|
@ -36,6 +36,10 @@ TopicStatusUpdater = Struct.new(:topic, :user) do
|
||||||
result = false if rc == 0
|
result = false if rc == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if status.manually_closing_topic?
|
||||||
|
DiscourseEvent.trigger(:topic_closed, topic)
|
||||||
|
end
|
||||||
|
|
||||||
if @topic_status_update
|
if @topic_status_update
|
||||||
if status.manually_closing_topic? || status.closing_topic?
|
if status.manually_closing_topic? || status.closing_topic?
|
||||||
topic.delete_topic_timer(TopicTimer.types[:close])
|
topic.delete_topic_timer(TopicTimer.types[:close])
|
||||||
|
|
|
@ -40,6 +40,20 @@ describe TopicStatusUpdater do
|
||||||
expect(last_post.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_minutes", count: 0))
|
expect(last_post.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_minutes", count: 0))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "triggers a DiscourseEvent on close" do
|
||||||
|
topic = create_topic
|
||||||
|
|
||||||
|
called = false
|
||||||
|
updater = -> (topic) { called = true }
|
||||||
|
|
||||||
|
DiscourseEvent.on(:topic_closed, &updater)
|
||||||
|
TopicStatusUpdater.new(topic, admin).update!("closed", true)
|
||||||
|
DiscourseEvent.off(:topic_closed, &updater)
|
||||||
|
|
||||||
|
expect(topic).to be_closed
|
||||||
|
expect(called).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
it "adds an autoclosed message based on last post" do
|
it "adds an autoclosed message based on last post" do
|
||||||
topic = create_topic
|
topic = create_topic
|
||||||
Fabricate(:post, topic: topic)
|
Fabricate(:post, topic: topic)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue