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

@ -37,7 +37,7 @@ module ChatSDK
#
# @see #create
def self.create_with_stream(**params, &block)
self.create(**params, streaming: true, &block)
self.create(**params, streaming: true, strip_whitespaces: false, &block)
end
# Streams to a specific chat message.
@ -114,6 +114,7 @@ module ChatSDK
streaming: false,
enforce_membership: false,
force_thread: false,
strip_whitespaces: true,
&block
)
message =
@ -128,6 +129,7 @@ module ChatSDK
streaming: streaming,
enforce_membership: enforce_membership,
force_thread: force_thread,
strip_whitespaces: strip_whitespaces,
) do
on_model_not_found(:channel) { raise "Couldn't find channel with id: `#{channel_id}`" }
on_model_not_found(:channel_membership) do
@ -179,6 +181,7 @@ module ChatSDK
message: self.message.message + raw,
guardian: self.guardian,
streaming: true,
strip_whitespaces: false,
) { on_failure { raise "Unexpected error" } }
self.message