DEV: allows to disable strip_whitespaces in messages (#26848)

The TextCleaner step has been moved from chat message’s validation to create_message/update_message services. It allows us to easily tweak part of its behavior depending on the needs.

For example we will now disable strip_whitespaces by default when streaming messages as we want to keep newlines and spaces at the end of the message.
This commit is contained in:
Joffrey JAFFEUX
2024-05-02 11:59:18 +02:00
committed by GitHub
parent 08e0a6b2cc
commit dda4bb0f7c
7 changed files with 68 additions and 19 deletions

View File

@ -150,8 +150,6 @@ describe ChatSDK::Message do
fab!(:message_1) { Fabricate(:chat_message, message: "first") }
it "enables streaming" do
initial_message = message_1.message
edit =
MessageBus
.track_publish("/chat/#{message_1.chat_channel.id}") do
@ -168,24 +166,22 @@ describe ChatSDK::Message do
end
describe ".stream" do
fab!(:message_1) { Fabricate(:chat_message, message: "first") }
fab!(:message_1) { Fabricate(:chat_message, message: "first\n") }
before { message_1.update!(streaming: true) }
it "streams" do
initial_message = message_1.message
edit =
MessageBus
.track_publish("/chat/#{message_1.chat_channel.id}") do
described_class.stream(
raw: " test",
raw: " test\n",
message_id: message_1.id,
guardian: message_1.user.guardian,
)
end
.find { |m| m.data["type"] == "edit" }
expect(edit.data["chat_message"]["message"]).to eq("first test")
expect(edit.data["chat_message"]["message"]).to eq("first\n test\n")
expect(message_1.reload.streaming).to eq(true)
end
end