FIX: Do not duplicate check when editing chat message to remove uploads (#19432)

There is no need to duplicate check chat messages when they are being
edited but not having their message text changed. This was leading to
a validation error when adding/removing an upload but not changing the
message text.
This commit is contained in:
Martin Brennan
2022-12-14 10:48:23 +10:00
committed by GitHub
parent 5c925f2db3
commit d147e92953
2 changed files with 60 additions and 10 deletions

View File

@ -37,7 +37,10 @@ class ChatMessage < ActiveRecord::Base
def validate_message(has_uploads:)
WatchedWordsValidator.new(attributes: [:message]).validate(self)
Chat::DuplicateMessageValidator.new(self).validate
if self.new_record? || self.changed.include?("message")
Chat::DuplicateMessageValidator.new(self).validate
end
if !has_uploads && message_too_short?
self.errors.add(
@ -52,10 +55,7 @@ class ChatMessage < ActiveRecord::Base
if message_too_long?
self.errors.add(
:base,
I18n.t(
"chat.errors.message_too_long",
maximum: SiteSetting.chat_maximum_message_length,
),
I18n.t("chat.errors.message_too_long", maximum: SiteSetting.chat_maximum_message_length),
)
end
end
@ -184,7 +184,7 @@ class ChatMessage < ActiveRecord::Base
markdown_it_rules: MARKDOWN_IT_RULES,
force_quote_link: true,
user_id: opts[:user_id],
hashtag_context: "chat-composer"
hashtag_context: "chat-composer",
)
result =