From f8673240710837db9d342a3cea860a3e46696aab Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 28 Jun 2023 23:52:53 +0100 Subject: [PATCH] feat: graphql for latest feed --- src/components/home/HomeFeed.tsx | 1 - src/models/home.model.ts | 87 +++++++++++++++++++++++++++----- 2 files changed, 74 insertions(+), 14 deletions(-) diff --git a/src/components/home/HomeFeed.tsx b/src/components/home/HomeFeed.tsx index a77eb16a..ba84dd5d 100644 --- a/src/components/home/HomeFeed.tsx +++ b/src/components/home/HomeFeed.tsx @@ -49,7 +49,6 @@ const PostCard = ({ simple && "opacity-90", isComment ? "bg-zinc-50" : "bg-white", )} - prefetch={false} > {!simple && }
diff --git a/src/models/home.model.ts b/src/models/home.model.ts index bcb3ec96..391a95ca 100644 --- a/src/models/home.model.ts +++ b/src/models/home.model.ts @@ -47,24 +47,83 @@ export async function getFeed({ } switch (type) { case "latest": { - let result = await indexer.note.getMany({ - sources: "xlog", - // tags: ["post"], - limit, - cursor, - includeCharacter: true, - excludeCharacterId: filter.latest, - } as any) + const result = await client + .query( + ` + query getNotes($filter: [Int!]) { + notes( + where: { + characterId: { + notIn: $filter + } + metadata: { + AND: [{ + content: { + path: "sources", + array_contains: "xlog" + } + }] + }, + }, + orderBy: [{ createdAt: desc }], + take: ${limit}, + ${ + cursor + ? ` + cursor: { + note_characterId_noteId_unique: { + characterId: ${cursor.split("_")[0]}, + noteId: ${cursor.split("_")[1]} + }, + },` + : "" + } + ) { + characterId + noteId + character { + handle + metadata { + content + } + } + createdAt + metadata { + uri + content + } + toNote { + characterId + noteId + character { + handle + metadata { + content + } + } + createdAt + metadata { + uri + content + } + } + } + }`, + { + filter: filter.latest, + }, + ) + .toPromise() const list = await Promise.all( - result.list - .filter((page) => { + result?.data?.notes + .filter((page: any) => { return !( page.metadata?.content?.tags?.includes("comment") && page.toNote?.metadata?.content?.tags?.includes("comment") ) }) - .map(async (page) => { + .map(async (page: any) => { const isComment = page.metadata?.content?.tags?.includes("comment") const expand = await expandCrossbellNote({ note: page, @@ -84,8 +143,10 @@ export async function getFeed({ return { list, - cursor: result.cursor, - count: result.count, + cursor: `${list[list.length - 1]?.characterId}_${ + list[list.length - 1]?.noteId + }`, + count: list?.length || 0, } } case "following": {