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ść...',
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;
}
},
};