A platform for community discussion. Free, open, simple.
FIX: no event when threading is disabled (#21439)
Joffrey JAFFEUX8f27913ec192
diff --git a/plugins/chat/lib/chat/message_creator.rb b/plugins/chat/lib/chat/message_creator.rbindex 2228c09cc19..c97b22a7913 100644--- a/plugins/chat/lib/chat/message_creator.rb+++ b/plugins/chat/lib/chat/message_creator.rb@@ -191,12 +191,14 @@ module Chat@chat_message.in_reply_to.thread_id = thread.idend- Chat::Publisher.publish_thread_created!(- @chat_message.chat_channel,- @chat_message.in_reply_to,- thread.id,- @staged_thread_id,- )+ if @chat_message.chat_channel.threading_enabled+ Chat::Publisher.publish_thread_created!(+ @chat_message.chat_channel,+ @chat_message.in_reply_to,+ thread.id,+ @staged_thread_id,+ )+ end@chat_message.thread_id = thread.iddiff --git a/plugins/chat/spec/components/chat/message_creator_spec.rb b/plugins/chat/spec/components/chat/message_creator_spec.rbindex 85127dbac18..a2e93e6c2f7 100644--- a/plugins/chat/spec/components/chat/message_creator_spec.rb+++ b/plugins/chat/spec/components/chat/message_creator_spec.rb@@ -440,25 +440,50 @@ describe Chat::MessageCreator doexpect(message.thread.original_message_user).to eq(reply_message.user)end- it "publishes the new thread" do- messages =- MessageBus.track_publish do- described_class.create(- chat_channel: public_chat_channel,- user: user1,- content: "this is a message",- in_reply_to_id: reply_message.id,- ).chat_message- end+ context "when threading is enabled" do+ it "publishes the new thread" do+ public_chat_channel.update!(threading_enabled: true)++ messages =+ MessageBus.track_publish do+ described_class.create(+ chat_channel: public_chat_channel,+ user: user1,+ content: "this is a message",+ in_reply_to_id: reply_message.id,+ ).chat_message+ end- thread_created_message = messages.find { |m| m.data["type"] == "thread_created" }- expect(thread_created_message.channel).to eq("/chat/#{public_chat_channel.id}")+ thread_created_message = messages.find { |m| m.data["type"] == "thread_created" }+ expect(thread_created_message.channel).to eq("/chat/#{public_chat_channel.id}")+ end+ end++ context "when threading is disabled" do+ it "doesn’t publish the new thread" do+ public_chat_channel.update!(threading_enabled: false)++ messages =+ MessageBus.track_publish do+ described_class.create(+ chat_channel: public_chat_channel,+ user: user1,+ content: "this is a message",+ in_reply_to_id: reply_message.id,+ ).chat_message+ end++ thread_created_message = messages.find { |m| m.data["type"] == "thread_created" }+ expect(thread_created_message).to be_nil+ endendcontext "when a staged_thread_id is provided" dofab!(:existing_thread) { Fabricate(:chat_thread, channel: public_chat_channel) }it "creates a thread and publishes with the staged id" do+ public_chat_channel.update!(threading_enabled: true)+messages =MessageBus.track_publish dodescribed_class.create(diff --git a/plugins/chat/spec/requests/chat_controller_spec.rb b/plugins/chat/spec/requests/chat_controller_spec.rbindex ce50fb698db..be56b8959fa 100644--- a/plugins/chat/spec/requests/chat_controller_spec.rb+++ b/plugins/chat/spec/requests/chat_controller_spec.rb@@ -388,6 +388,7 @@ RSpec.describe Chat::ChatController docontext "when sending a message in a staged thread" doit "creates the thread and publishes with the staged id" dosign_in(user)+ chat_channel.update!(threading_enabled: true)messages =MessageBus.track_publish do