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
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:
parent
b2f24f02bc
commit
1105099177
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user