clear height while sending or clearing, also fix #572 in the process

This commit is contained in:
Bruno Windels 2021-11-05 18:36:59 +01:00
parent fc1b9abe66
commit 44e7e25cab

View file

@ -34,7 +34,11 @@ export class MessageComposer extends TemplateView {
onKeydown: e => this._onKeyDown(e),
onInput: () => {
vm.setInput(this._input.value);
if (this._input.value) {
this._adjustHeight();
} else {
this._clearHeight();
}
},
placeholder: vm.isEncrypted ? "Send an encrypted message…" : "Send a message…",
rows: "1"
@ -85,9 +89,24 @@ export class MessageComposer extends TemplateView {
async _trySend() {
this._input.focus();
if (await this.value.sendMessage(this._input.value)) {
this._input.value = "";
// we clear the composer while enqueuing
// and restore it when that didn't work somehow
// to prevent the user from sending the message
// every time they hit enter while it's still enqueuing.
const {value} = this._input;
const restoreValue = () => {
this._input.value = value;
this._adjustHeight();
};
this._input.value = "";
this._clearHeight();
try {
if (!await this.value.sendMessage(value)) {
restoreValue();
}
} catch (err) {
restoreValue();
console.error(err);
}
}
@ -125,4 +144,8 @@ export class MessageComposer extends TemplateView {
});
}
_clearHeight() {
this._input.style.removeProperty("height");
}
}