fix(messages): dedup optimistic vs server messages by content matching
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

This commit is contained in:
Maciej Pienczyn 2026-03-28 17:17:25 +01:00
parent b2f24f02bc
commit 1105099177

View File

@ -727,9 +727,23 @@
if (!state.messages[convId]) state.messages[convId] = [];
// Dedup: skip if message with this ID already exists
if (msg.id && state.messages[convId].some(function(m) { return m.id === msg.id; })) {
return; // Already displayed
}
// Dedup: skip if exact ID match OR if this is a server response for an optimistic message
var dominated = state.messages[convId].some(function(m) {
if (m.id === msg.id) return true; // Exact ID match
// Check if an optimistic message matches this server response
if (m._optimistic && msg.sender_id && m.sender_id === msg.sender_id) {
var mContent = (m.content || '').replace(/<[^>]*>/g, '').trim();
var msgContent = (msg.content || '').replace(/<[^>]*>/g, '').trim();
if (mContent === msgContent) {
// Replace optimistic with real — update ID for future dedup
m.id = msg.id;
m._optimistic = false;
return true;
}
}
return false;
});
if (dominated) return;
state.messages[convId].push(msg);
if (convId !== state.currentConversationId) return;