From 5adc6db03162d99b429c2d4833e44e74fde99a65 Mon Sep 17 00:00:00 2001 From: Maciej Pienczyn Date: Sat, 28 Mar 2026 15:50:14 +0100 Subject: [PATCH] fix(messages): prevent double message sending on Enter key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added _isSending flag to Composer.send() — blocks concurrent sends - Added Quill keyboard binding override for Enter (handler returns false) - Added stopImmediatePropagation() to DOM keydown handler - Added _isCreating flag to NewConversation.send() - Flags reset in finally blocks to handle errors gracefully Fixes: messages appearing twice when user presses Enter Co-Authored-By: Claude Opus 4.6 (1M context) --- static/js/conversations.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/static/js/conversations.js b/static/js/conversations.js index 5c781c3..7695e23 100644 --- a/static/js/conversations.js +++ b/static/js/conversations.js @@ -1203,6 +1203,19 @@ placeholder: 'Napisz wiadomość...', modules: { toolbar: [['bold', 'italic'], ['link'], ['clean']], + keyboard: { + bindings: { + enter: { + key: 13, + handler: function() { Composer.send(); return false; } + }, + shiftEnter: { + key: 13, + shiftKey: true, + handler: function() { return true; } // Allow newline + } + } + } }, }); @@ -1211,7 +1224,9 @@ if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); e.stopPropagation(); + e.stopImmediatePropagation(); Composer.send(); + return false; } }); @@ -1254,12 +1269,14 @@ send: async function () { if (!state.currentConversationId || !state.quill) return; + if (state._isSending) return; // Prevent double send var html = state.quill.root.innerHTML; var text = state.quill.getText().trim(); if (!text && !state.attachedFiles.length) return; + state._isSending = true; var convId = state.currentConversationId; try { @@ -1296,6 +1313,8 @@ }); } catch (e) { alert('Nie udało się wysłać wiadomości: ' + e.message); + } finally { + state._isSending = false; } }, @@ -1963,6 +1982,8 @@ alert('Wybierz co najmniej jednego odbiorcę'); return; } + if (state._isCreating) return; // Prevent double send + state._isCreating = true; var messageContent = ''; if (state.newMessageQuill) { @@ -2005,6 +2026,8 @@ ConversationList.selectConversation(result.id); } catch (e) { alert('Nie udało się utworzyć konwersacji: ' + e.message); + } finally { + state._isCreating = false; } }, };