fix(messages): prevent double message sending on Enter key
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions

- 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) <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-03-28 15:50:14 +01:00
parent b05429bfe3
commit 5adc6db031

View File

@ -1203,6 +1203,19 @@
placeholder: 'Napisz wiadomość...', placeholder: 'Napisz wiadomość...',
modules: { modules: {
toolbar: [['bold', 'italic'], ['link'], ['clean']], 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) { if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
e.stopImmediatePropagation();
Composer.send(); Composer.send();
return false;
} }
}); });
@ -1254,12 +1269,14 @@
send: async function () { send: async function () {
if (!state.currentConversationId || !state.quill) return; if (!state.currentConversationId || !state.quill) return;
if (state._isSending) return; // Prevent double send
var html = state.quill.root.innerHTML; var html = state.quill.root.innerHTML;
var text = state.quill.getText().trim(); var text = state.quill.getText().trim();
if (!text && !state.attachedFiles.length) return; if (!text && !state.attachedFiles.length) return;
state._isSending = true;
var convId = state.currentConversationId; var convId = state.currentConversationId;
try { try {
@ -1296,6 +1313,8 @@
}); });
} catch (e) { } catch (e) {
alert('Nie udało się wysłać wiadomości: ' + e.message); 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ę'); alert('Wybierz co najmniej jednego odbiorcę');
return; return;
} }
if (state._isCreating) return; // Prevent double send
state._isCreating = true;
var messageContent = ''; var messageContent = '';
if (state.newMessageQuill) { if (state.newMessageQuill) {
@ -2005,6 +2026,8 @@
ConversationList.selectConversation(result.id); ConversationList.selectConversation(result.id);
} catch (e) { } catch (e) {
alert('Nie udało się utworzyć konwersacji: ' + e.message); alert('Nie udało się utworzyć konwersacji: ' + e.message);
} finally {
state._isCreating = false;
} }
}, },
}; };