Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit e11c44a

Browse files
committed
OPTIMIZE
1 parent 59b1970 commit e11c44a

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

src/routes/Chat.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -274,25 +274,43 @@ export function Chat() {
274274
// "npub1qf8e8cvfp60ywrah984zgsn8veggcrsv2cvttdr47tgz05ypf5yszwx308",
275275
contact.npub,
276276
20n,
277+
undefined,
277278
refetchingTimestamp ? refetchingTimestamp : undefined
278279
);
279280

280-
const lastConvo = info.value as CombinedMessagesAndActivity[];
281-
if (
282-
lastConvo &&
283-
lastConvo.length === convo.length + activity.length
284-
) {
285-
console.log("no new messages or activity");
286-
return lastConvo;
287-
}
288-
289-
console.log("dms", convo);
290-
291281
setLastFetch(BigInt(Math.floor(Date.now() / 1000)));
292282

293283
const dms = convo as FakeDirectMessage[];
294284
const acts = activity as IActivityItem[];
295285

286+
if (info.refetching) {
287+
const lastConvo =
288+
info.value as CombinedMessagesAndActivity[];
289+
290+
let lastConvoActivity = 0;
291+
292+
// TODO: remove this once we can do "since" for activity as well
293+
for (let i = 0; i < lastConvo.length; i++) {
294+
if (lastConvo[i].kind === "activity") {
295+
lastConvoActivity += 1;
296+
}
297+
}
298+
299+
if (
300+
convo.length === 0 &&
301+
activity.length === lastConvoActivity
302+
) {
303+
console.log("no new messages or activity");
304+
// Return early because we've determined there's nothing new
305+
return lastConvo;
306+
} else {
307+
console.log("new messages or activity");
308+
dms.push(convo);
309+
}
310+
}
311+
312+
console.log("dms", convo);
313+
296314
// Combine both arrays into an array of CombinedMessagesAndActivity, then sort by date
297315
const combined = [
298316
...dms.map((dm) => ({

0 commit comments

Comments
 (0)