compose: Don't allow same message to be sent twice.

It is possible to send the message twice by clicking send button
very quickly twice or by pressing enter and send button simultaneously.

This can be easily reproduced for large messages sent in a stream
narrow. Hard to reproduce for small messages or in PM narrows.

I was not able to reproduce locally, but was able to reproduce on
chat.zulip.org. So, this is an untested bug fix.

Fixes #22562
This commit is contained in:
Aman Agrawal
2022-07-28 07:31:57 +00:00
committed by Tim Abbott
parent 5fd4d3f053
commit a13058223d
3 changed files with 17 additions and 0 deletions

View File

@@ -290,7 +290,17 @@ export function enter_with_preview_open(ctrl_pressed = false) {
}
}
// Common entrypoint for asking the server to send the message
// currently drafted in the compose box, including for scheduled
// messages.
export function finish() {
if (compose_ui.compose_spinner_visible) {
// Avoid sending a message twice in parallel in races where
// the user clicks the `Send` button very quickly twice or
// presses enter and the send button simultaneously.
return undefined;
}
clear_preview_area();
clear_invites();
clear_private_stream_alert();