Skip to content

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

FIX: correct in_thread? message logic (#27151)

Joffrey JAFFEUXb3802e12f036
diff --git a/plugins/chat/app/models/chat/message.rb b/plugins/chat/app/models/chat/message.rb
index 32cf71b1092..1e92d77f931 100644
--- a/plugins/chat/app/models/chat/message.rb
+++ b/plugins/chat/app/models/chat/message.rb
@@ -266,7 +266,7 @@ module Chat
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 264c3f8bfff..924aa83ecec 100644
--- a/plugins/chat/spec/models/chat/message_spec.rb
+++ b/plugins/chat/spec/models/chat/message_spec.rb
@@ -11,6 +11,40 @@ describe Chat::Message do
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("<h1>test</h1>")