Skip to content

A platform for community discussion. Free, open, simple.

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

Joffrey JAFFEUX89259205d639
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js
index f57672e0aeb..246736584e0 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js
@@ -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);
+ }
}
diff --git a/plugins/chat/spec/system/chat_composer_spec.rb b/plugins/chat/spec/system/chat_composer_spec.rb
index d0eb36235e1..06735f56832 100644
--- a/plugins/chat/spec/system/chat_composer_spec.rb
+++ b/plugins/chat/spec/system/chat_composer_spec.rb
@@ -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