From 571ee122f6ea034e0d232d8fa309af1d62114b13 Mon Sep 17 00:00:00 2001 From: ajvpot <553597+ajvpot@users.noreply.github.com> Date: Mon, 28 Jul 2025 00:00:00 +0000 Subject: [PATCH] auto refresh after time is still messed up --- src/components/ChatBox.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/ChatBox.tsx b/src/components/ChatBox.tsx index e4ad510..f241802 100644 --- a/src/components/ChatBox.tsx +++ b/src/components/ChatBox.tsx @@ -87,7 +87,10 @@ export default function ChatBox({ showAllMessagesTab = false, className = "", st if (fetchNewer) { // Fetch newer messages using the most recent message timestamp const mostRecentTimestamp = messages.length > 0 ? messages[0].ingest_timestamp : undefined; - if (mostRecentTimestamp) url += `&after=${encodeURIComponent(mostRecentTimestamp)}`; + if (mostRecentTimestamp) { + // Ensure we use the exact UTC timestamp format for the API + url += `&after=${encodeURIComponent(mostRecentTimestamp)}`; + } } else if (before) { // Fetch older messages using before parameter url += `&before=${encodeURIComponent(before)}`; @@ -97,8 +100,14 @@ export default function ChatBox({ showAllMessagesTab = false, className = "", st const data = await res.json(); if (Array.isArray(data)) { if (fetchNewer && data.length > 0) { - // Add newer messages to the beginning (most recent first) - setMessages((prev) => [...data, ...prev]); + // Filter out any duplicate messages by ingest_timestamp to prevent duplicates + const existingTimestamps = new Set(messages.map(msg => msg.ingest_timestamp)); + const newMessages = data.filter(msg => !existingTimestamps.has(msg.ingest_timestamp)); + + if (newMessages.length > 0) { + // Add newer messages to the beginning (most recent first) + setMessages((prev) => [...newMessages, ...prev]); + } } else { setMessages((prev) => replace ? data : [...prev, ...data]); setHasMore(data.length === PAGE_SIZE);