FIX: no event when threading is disabled ()

Every replies creates a thread, even when threading is disabled. This is how we ensure we can go back and forth. However, a message bus event should only be published when threading is enabled, otherwise frontend will attempt to display a thread which is not possible when disabled.

This fixes a silent background 404 when doing a reply in a direct message channel or a non threading enabled category channel.
This commit is contained in:
Joffrey JAFFEUX 2023-05-09 10:11:29 +02:00 committed by GitHub
parent bc847e54d4
commit 8f27913ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 18 deletions
plugins/chat

@ -191,12 +191,14 @@ module Chat
@chat_message.in_reply_to.thread_id = thread.id
end
Chat::Publisher.publish_thread_created!(
@chat_message.chat_channel,
@chat_message.in_reply_to,
thread.id,
@staged_thread_id,
)
if @chat_message.chat_channel.threading_enabled
Chat::Publisher.publish_thread_created!(
@chat_message.chat_channel,
@chat_message.in_reply_to,
thread.id,
@staged_thread_id,
)
end
@chat_message.thread_id = thread.id

@ -440,25 +440,50 @@ describe Chat::MessageCreator do
expect(message.thread.original_message_user).to eq(reply_message.user)
end
it "publishes the new thread" do
messages =
MessageBus.track_publish do
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "this is a message",
in_reply_to_id: reply_message.id,
).chat_message
end
context "when threading is enabled" do
it "publishes the new thread" do
public_chat_channel.update!(threading_enabled: true)
thread_created_message = messages.find { |m| m.data["type"] == "thread_created" }
expect(thread_created_message.channel).to eq("/chat/#{public_chat_channel.id}")
messages =
MessageBus.track_publish do
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "this is a message",
in_reply_to_id: reply_message.id,
).chat_message
end
thread_created_message = messages.find { |m| m.data["type"] == "thread_created" }
expect(thread_created_message.channel).to eq("/chat/#{public_chat_channel.id}")
end
end
context "when threading is disabled" do
it "doesn’t publish the new thread" do
public_chat_channel.update!(threading_enabled: false)
messages =
MessageBus.track_publish do
described_class.create(
chat_channel: public_chat_channel,
user: user1,
content: "this is a message",
in_reply_to_id: reply_message.id,
).chat_message
end
thread_created_message = messages.find { |m| m.data["type"] == "thread_created" }
expect(thread_created_message).to be_nil
end
end
context "when a staged_thread_id is provided" do
fab!(:existing_thread) { Fabricate(:chat_thread, channel: public_chat_channel) }
it "creates a thread and publishes with the staged id" do
public_chat_channel.update!(threading_enabled: true)
messages =
MessageBus.track_publish do
described_class.create(

@ -388,6 +388,7 @@ RSpec.describe Chat::ChatController do
context "when sending a message in a staged thread" do
it "creates the thread and publishes with the staged id" do
sign_in(user)
chat_channel.update!(threading_enabled: true)
messages =
MessageBus.track_publish do