Skip to content

A platform for community discussion. Free, open, simple.

FIX: Publish the topic instead of the post to refresh topic titles (#34961)

Natalie Tay1e1d71af62dd
diff --git a/plugins/discourse-ai/app/jobs/regular/detect_translate_topic.rb b/plugins/discourse-ai/app/jobs/regular/detect_translate_topic.rb
index 10b301b4fdd..7a45b374879 100644
--- a/plugins/discourse-ai/app/jobs/regular/detect_translate_topic.rb
+++ b/plugins/discourse-ai/app/jobs/regular/detect_translate_topic.rb
@@ -56,7 +56,7 @@ module Jobs
end
end
- MessageBus.publish("/topic/#{topic.id}", type: :localized, id: 1)
+ MessageBus.publish("/topic/#{topic.id}", reload_topic: true)
end
end
end
diff --git a/plugins/discourse-ai/spec/jobs/regular/detect_translate_topic_spec.rb b/plugins/discourse-ai/spec/jobs/regular/detect_translate_topic_spec.rb
index c259cb15168..32d952a1525 100644
--- a/plugins/discourse-ai/spec/jobs/regular/detect_translate_topic_spec.rb
+++ b/plugins/discourse-ai/spec/jobs/regular/detect_translate_topic_spec.rb
@@ -190,5 +190,19 @@ describe Jobs::DetectTranslateTopic do
job.execute({ topic_id: personal_pm_topic.id, force: true })
end
end
+
+ it "publishes a MessageBus event to update the topic" do
+ allow(DiscourseAi::Translation::TopicLocaleDetector).to receive(:detect_locale).with(
+ group_pm_topic,
+ ).and_return("en")
+ allow(DiscourseAi::Translation::TopicLocalizer).to receive(:localize).and_return(true)
+
+ message =
+ MessageBus.track_publish { job.execute({ topic_id: group_pm_topic.id, force: true }) }
+
+ expect(message.count).to eq(1)
+ expect(message.first.channel).to eq("/topic/#{group_pm_topic.id}")
+ expect(message.first.data).to eq(reload_topic: true)
+ end
end
end