Skip to content

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

FIX: prevents saving draft in incorrect channel (#21741)

Joffrey JAFFEUX398eaf0429eb
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js
index 771efb0053d..82a7085671d 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-composer.js
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer.js
@@ -146,8 +146,11 @@ export default class ChatComposer extends Component {
@action
didUpdateChannel() {
+ this.cancelPersistDraft();
+
if (!this.args.channel) {
this.composer.message = null;
+ return;
}
this.composer.message =
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/composer/channel.js b/plugins/chat/assets/javascripts/discourse/components/chat/composer/channel.js
index 7ec57d2a1f3..49a67daa4b7 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat/composer/channel.js
+++ b/plugins/chat/assets/javascripts/discourse/components/chat/composer/channel.js
@@ -29,16 +29,15 @@ export default class ChatComposerChannel extends ChatComposer {
this._persistHandler = discourseDebounce(
this,
this._debouncedPersistDraft,
+ this.args.channel.id,
+ this.currentMessage.toJSONDraft(),
2000
);
}
@action
- _debouncedPersistDraft() {
- this.chatApi.saveDraft(
- this.args.channel.id,
- this.currentMessage.toJSONDraft()
- );
+ _debouncedPersistDraft(channelId, jsonDraft) {
+ this.chatApi.saveDraft(channelId, jsonDraft);
}
get placeholder() {