Skip to content

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

FIX: Publish new DM channel after transaction commits (#40148)

Martin Brennan34ad77e8b1cc
diff --git a/plugins/chat/app/services/chat/create_message.rb b/plugins/chat/app/services/chat/create_message.rb
index c409c8db47d..0867256557b 100644
--- a/plugins/chat/app/services/chat/create_message.rb
+++ b/plugins/chat/app/services/chat/create_message.rb
@@ -83,9 +83,9 @@ module Chat
step :create_webhook_event
step :update_channel_last_message
step :update_membership_last_read
- step :process_direct_message_channel
end
+ step :process_direct_message_channel
step :publish_new_thread
step :process
step :publish_user_tracking_state
diff --git a/plugins/chat/spec/services/chat/create_message_spec.rb b/plugins/chat/spec/services/chat/create_message_spec.rb
index a819a8a6484..75f6beb1107 100644
--- a/plugins/chat/spec/services/chat/create_message_spec.rb
+++ b/plugins/chat/spec/services/chat/create_message_spec.rb
@@ -182,6 +182,16 @@ RSpec.describe Chat::CreateMessage do
)
result
end
+
+ it "processes the direct message channel outside of the service transaction" do
+ initial_depth = ActiveRecord::Base.connection.open_transactions
+ transaction_depth_when_called = nil
+ Chat::Action::PublishAndFollowDirectMessageChannel
+ .expects(:call)
+ .with { transaction_depth_when_called = ActiveRecord::Base.connection.open_transactions }
+ result
+ expect(transaction_depth_when_called).to eq(initial_depth)
+ end
end
shared_examples "a message in a thread" do