A platform for community discussion. Free, open, simple.
DEV: adds a `:chat_thread_created` trigger (#24133)
Joffrey JAFFEUXdb880d8ed71a
diff --git a/plugins/chat/app/services/chat/create_thread.rb b/plugins/chat/app/services/chat/create_thread.rbindex 683d895bb6d..090009bb960 100644--- a/plugins/chat/app/services/chat/create_thread.rb+++ b/plugins/chat/app/services/chat/create_thread.rb@@ -26,6 +26,7 @@ module Chatstep :associate_thread_to_messagestep :fetch_membershipstep :publish_new_thread+ step :trigger_chat_thread_created_eventend# @!visibility private@@ -84,5 +85,9 @@ module Chatdef publish_new_thread(channel:, original_message:, **)::Chat::Publisher.publish_thread_created!(channel, original_message, context.thread.id)end++ def trigger_chat_thread_created_event+ ::DiscourseEvent.trigger(:chat_thread_created, context.thread)+ endendenddiff --git a/plugins/chat/spec/services/chat/create_thread_spec.rb b/plugins/chat/spec/services/chat/create_thread_spec.rbindex c73a202fa89..c7cb6cc9d43 100644--- a/plugins/chat/spec/services/chat/create_thread_spec.rb+++ b/plugins/chat/spec/services/chat/create_thread_spec.rb@@ -51,6 +51,12 @@ RSpec.describe Chat::CreateThread doexpect(message.data["type"]).to eq("thread_created")end+ it "triggers a discourse event `chat_thread_created`" do+ event = DiscourseEvent.track_events(:chat_thread_created) { result }.first++ expect(event[:params][0]).to eq(result.thread)+ end+it "sets the title when existing" doparams[:title] = "Restaurant for Saturday"result