Skip to content

Commit

Permalink
OPTIMIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul committed Feb 1, 2024
1 parent 59b1970 commit e11c44a
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/routes/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand Down

0 comments on commit e11c44a

Please sign in to comment.