Skip to content

Commit

Permalink
FIX: correct in_thread? message logic (#27151)
Browse files Browse the repository at this point in the history
A message is in a thread if:
- it has a thread_id
- it is in threading_enabled channel OR the associated thread is marked as `force`
  • Loading branch information
jjaffeux committed May 23, 2024
1 parent f84eda7 commit b3802e1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/chat/app/models/chat/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
34 changes: 34 additions & 0 deletions plugins/chat/spec/models/chat/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("<h1>test</h1>")
Expand Down

1 comment on commit b3802e1

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/ai-chat-threads-not-shown-after-latest-update/308541/11

Please sign in to comment.