FIX: do not delete empty message with uploads (#23177)

Prior to this fix when editing a message containing only upload, if we would save it, it would delete it by considering it empty.
This commit is contained in:
Joffrey JAFFEUX 2023-08-22 15:21:21 +02:00 committed by GitHub
parent 687c6c7515
commit 89259205d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 7 deletions

View File

@ -126,10 +126,14 @@ export default class ChatComposer extends Component {
const minLength = this.siteSettings.chat_minimum_message_length || 1;
return (
this.currentMessage?.message?.length >= minLength ||
(this.canAttachUploads && this.currentMessage?.uploads?.length > 0)
(this.canAttachUploads && this.hasUploads)
);
}
get hasUploads() {
return this.currentMessage?.uploads?.length > 0;
}
get sendEnabled() {
return (
(this.hasContent || this.currentMessage?.editing) &&
@ -229,14 +233,10 @@ export default class ChatComposer extends Component {
if (
this.currentMessage.editing &&
!this.hasUploads &&
this.currentMessage.message.length === 0
) {
new ChatMessageInteractor(
getOwner(this),
this.currentMessage,
this.context
).delete();
this.reset(this.args.channel, this.args.thread);
this.#deleteEmptyMessage();
return;
}
@ -585,4 +585,13 @@ export default class ChatComposer extends Component {
#isAutocompleteDisplayed() {
return document.querySelector(".autocomplete");
}
#deleteEmptyMessage() {
new ChatMessageInteractor(
getOwner(this),
this.currentMessage,
this.context
).delete();
this.reset(this.args.channel, this.args.thread);
}
}

View File

@ -104,6 +104,25 @@ RSpec.describe "Chat composer", type: :system do
expect(channel_page.messages).to have_message(deleted: 1)
end
context "with uploads" do
fab!(:upload_reference) do
Fabricate(
:upload_reference,
target: message_1,
upload: Fabricate(:upload, user: current_user),
)
end
it "doesnt delete the message" do
chat_page.visit_channel(channel_1)
channel_page.composer.edit_last_message_shortcut
channel_page.composer.fill_in(with: "")
channel_page.click_send_message
expect(channel_page.messages).to have_message(id: message_1.id)
end
end
end
context "when posting a message with length equal to minimum length" do