diff --git a/plugins/chat/app/models/chat/message.rb b/plugins/chat/app/models/chat/message.rb index 32cf71b10928..1e92d77f9312 100644 --- a/plugins/chat/app/models/chat/message.rb +++ b/plugins/chat/app/models/chat/message.rb @@ -266,7 +266,7 @@ def upsert_mentions end def in_thread? - self.thread_id.present? && self.chat_channel.threading_enabled + self.thread_id.present? && (self.chat_channel.threading_enabled || self.thread&.force) end def thread_reply? diff --git a/plugins/chat/spec/models/chat/message_spec.rb b/plugins/chat/spec/models/chat/message_spec.rb index 264c3f8bfff5..924aa83ececa 100644 --- a/plugins/chat/spec/models/chat/message_spec.rb +++ b/plugins/chat/spec/models/chat/message_spec.rb @@ -11,6 +11,40 @@ it { is_expected.to validate_length_of(:cooked).is_at_most(20_000) } end + describe ".in_thread?" do + context "when in a thread enabled channel" do + fab!(:message) do + Fabricate( + :chat_message, + thread_id: 1, + chat_channel: Fabricate(:chat_channel, threading_enabled: true), + ) + end + + it "returns true for messages in a thread" do + expect(message.in_thread?).to eq(true) + end + + it "returns false for messages not in a thread" do + message.update!(thread_id: nil) + expect(message.in_thread?).to eq(false) + end + end + + context "when the thread is forced" do + fab!(:message) { Fabricate(:chat_message, thread: Fabricate(:chat_thread, force: true)) } + + it "returns true for messages in a thread" do + expect(message.in_thread?).to eq(true) + end + + it "returns false for messages not in a thread" do + message.update!(thread_id: nil) + expect(message.in_thread?).to eq(false) + end + end + end + describe ".cook" do it "does not support HTML tags" do cooked = described_class.cook("

test

")