fix(messages): time-based dedup for optimistic messages (10s window)
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
b944042a85
commit
d8db218df2
@ -727,15 +727,14 @@
|
||||
if (!state.messages[convId]) state.messages[convId] = [];
|
||||
|
||||
// Dedup: skip if message with this ID already exists
|
||||
// Dedup: skip if exact ID match OR if this is a server response for an optimistic message
|
||||
// Dedup: skip if exact ID match OR if optimistic message from same sender within 10s
|
||||
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.id === msg.id) return true;
|
||||
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
|
||||
// Time-based match: if optimistic msg was sent within 10s, it's the same
|
||||
var mTime = new Date(m.created_at).getTime();
|
||||
var msgTime = new Date(msg.created_at).getTime();
|
||||
if (Math.abs(mTime - msgTime) < 10000) {
|
||||
m.id = msg.id;
|
||||
m._optimistic = false;
|
||||
return true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user