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

This commit regroups 3 changes
- serializes channel ID and json draft when calling the debouncer instead of inside the debounced function, it seems very unlikely to happen, but in a case where the debouncing wouldn't be canceled and the new message not set yet, we could save the draft on an invalid channel
- cancel persist draft handler when changing channel
- ensures we exit early when channel is not set
This commit is contained in:
Joffrey JAFFEUX 2023-05-25 09:29:31 +02:00 committed by GitHub
parent 082921c4c8
commit 398eaf0429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -146,8 +146,11 @@ export default class ChatComposer extends Component {
@action @action
didUpdateChannel() { didUpdateChannel() {
this.cancelPersistDraft();
if (!this.args.channel) { if (!this.args.channel) {
this.composer.message = null; this.composer.message = null;
return;
} }
this.composer.message = this.composer.message =

View File

@ -29,16 +29,15 @@ export default class ChatComposerChannel extends ChatComposer {
this._persistHandler = discourseDebounce( this._persistHandler = discourseDebounce(
this, this,
this._debouncedPersistDraft, this._debouncedPersistDraft,
this.args.channel.id,
this.currentMessage.toJSONDraft(),
2000 2000
); );
} }
@action @action
_debouncedPersistDraft() { _debouncedPersistDraft(channelId, jsonDraft) {
this.chatApi.saveDraft( this.chatApi.saveDraft(channelId, jsonDraft);
this.args.channel.id,
this.currentMessage.toJSONDraft()
);
} }
get placeholder() { get placeholder() {