mirror of
https://github.com/discourse/discourse.git
synced 2025-04-01 00:46:05 +08:00
FIX: no event when threading is disabled (#21439)
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:
parent
bc847e54d4
commit
8f27913ec1
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user