fix(messages): root cause of double messages — polling re-adds sent message
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
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
The actual bug: Composer.send() appends message to DOM via appendMessage(), then 1-5s later the polling loop fetches the same message from API and appends it again. Fix: track sent messages in state.messages[convId] so the polling dedup check (msg.id > newestId) filters them out. Also removed debug logging. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9151e4efa0
commit
720d7a2d7d
@ -183,8 +183,6 @@ def get_messages(conv_id):
|
||||
@member_required
|
||||
def send_message(conv_id):
|
||||
"""Send a message to a conversation."""
|
||||
import logging
|
||||
logging.getLogger(__name__).info(f"[MSG-DEBUG] send_message called: conv={conv_id}, user={current_user.id}, method={request.method}")
|
||||
db = SessionLocal()
|
||||
try:
|
||||
# Verify membership
|
||||
|
||||
@ -1211,7 +1211,6 @@
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
console.log('[MSG-DEBUG] Enter keydown captured, _isSending=' + state._isSending + ', _lastSendTime=' + state._lastSendTime);
|
||||
Composer.send();
|
||||
}
|
||||
}, true);
|
||||
@ -1225,7 +1224,6 @@
|
||||
var sendBtn = document.getElementById('sendBtn');
|
||||
if (sendBtn) {
|
||||
sendBtn.addEventListener('click', function () {
|
||||
console.log('[MSG-DEBUG] Send BUTTON clicked');
|
||||
Composer.send();
|
||||
});
|
||||
}
|
||||
@ -1259,12 +1257,10 @@
|
||||
// Double-send guard: flag + timestamp debounce (500ms)
|
||||
var now = Date.now();
|
||||
if (state._isSending || (state._lastSendTime && now - state._lastSendTime < 500)) {
|
||||
console.log('[MSG-DEBUG] send() BLOCKED: _isSending=' + state._isSending + ', timeSinceLast=' + (now - (state._lastSendTime || 0)) + 'ms');
|
||||
return;
|
||||
}
|
||||
state._isSending = true;
|
||||
state._lastSendTime = now;
|
||||
console.log('[MSG-DEBUG] send() EXECUTING at ' + now);
|
||||
|
||||
var html = state.quill.root.innerHTML;
|
||||
var text = state.quill.getText().trim();
|
||||
@ -1294,8 +1290,10 @@
|
||||
if (replyPreview) replyPreview.style.display = 'none';
|
||||
Composer.renderAttachments();
|
||||
|
||||
// Append the sent message
|
||||
// Append the sent message and track it so polling doesn't duplicate
|
||||
ChatView.appendMessage(result);
|
||||
if (!state.messages[convId]) state.messages[convId] = [];
|
||||
state.messages[convId].push(result);
|
||||
|
||||
// Update conversation in list
|
||||
ConversationList.updateConversation(convId, {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user