FIX: don't trigger `topic_created` event for reply posts via email. (#15485)

Previously, we incorrectly triggered `topic_created` events when the posts are created via email since we didn't check the post number.
This commit is contained in:
Vinoth Kannan 2022-01-10 13:54:10 +05:30 committed by GitHub
parent f99ade3ce5
commit f614b30032
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -1308,7 +1308,7 @@ module Email
import_mode: options[:import_mode],
post_alert_options: options[:post_alert_options]
).enqueue_jobs
DiscourseEvent.trigger(:topic_created, result.post.topic, options, user)
DiscourseEvent.trigger(:topic_created, result.post.topic, options, user) if result.post.is_first_post?
DiscourseEvent.trigger(:post_created, result.post, options, user)
end

View File

@ -340,7 +340,12 @@ describe Email::Receiver do
expect { process(:like) }.to raise_error(Email::Receiver::InvalidPostAction)
end
it "works" do
it "creates a new reply post" do
handler_calls = 0
handler = proc { |_| handler_calls += 1 }
DiscourseEvent.on(:topic_created, &handler)
expect { process(:text_reply) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to eq("This is a text reply :)\n\nEmail parsing should not break because of a UTF-8 character: ")
expect(topic.posts.last.via_email).to eq(true)
@ -348,6 +353,9 @@ describe Email::Receiver do
expect { process(:html_reply) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to eq("This is a **HTML** reply ;)")
DiscourseEvent.off(:topic_created, &handler)
expect(handler_calls).to eq(0)
end
it "stores the created_via source against the incoming email" do