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:
parent
082921c4c8
commit
398eaf0429
|
@ -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 =
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in New Issue