diff --git a/src/routes/Chat.tsx b/src/routes/Chat.tsx index ef6433b7c..b10593062 100644 --- a/src/routes/Chat.tsx +++ b/src/routes/Chat.tsx @@ -274,25 +274,43 @@ export function Chat() { // "npub1qf8e8cvfp60ywrah984zgsn8veggcrsv2cvttdr47tgz05ypf5yszwx308", contact.npub, 20n, + undefined, refetchingTimestamp ? refetchingTimestamp : undefined ); - const lastConvo = info.value as CombinedMessagesAndActivity[]; - if ( - lastConvo && - lastConvo.length === convo.length + activity.length - ) { - console.log("no new messages or activity"); - return lastConvo; - } - - console.log("dms", convo); - setLastFetch(BigInt(Math.floor(Date.now() / 1000))); const dms = convo as FakeDirectMessage[]; const acts = activity as IActivityItem[]; + if (info.refetching) { + const lastConvo = + info.value as CombinedMessagesAndActivity[]; + + let lastConvoActivity = 0; + + // TODO: remove this once we can do "since" for activity as well + for (let i = 0; i < lastConvo.length; i++) { + if (lastConvo[i].kind === "activity") { + lastConvoActivity += 1; + } + } + + if ( + convo.length === 0 && + activity.length === lastConvoActivity + ) { + console.log("no new messages or activity"); + // Return early because we've determined there's nothing new + return lastConvo; + } else { + console.log("new messages or activity"); + dms.push(convo); + } + } + + console.log("dms", convo); + // Combine both arrays into an array of CombinedMessagesAndActivity, then sort by date const combined = [ ...dms.map((dm) => ({