a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

paginate feed!

+28 -5
+28 -5
feeds/index.ts
··· 23 23 ], 24 24 }); 25 25 }); 26 + //Cursor format ts::uri 26 27 27 28 app.get("/xrpc/app.bsky.feed.getFeedSkeleton", async (c) => { 28 29 let auth = await validateAuth(c.req, serviceDid); 30 + let cursor = c.req.query("cursor"); 29 31 if (!auth) return c.json({ feed: [] }); 30 32 31 33 let { data: publications } = await supabaseServerClient ··· 47 49 ? new Date(bRecord.publishedAt) 48 50 : new Date(0); 49 51 return bDate.getTime() - aDate.getTime(); // Sort by most recent first 50 - }) 51 - .flatMap((p) => { 52 + }); 53 + let posts; 54 + if (!cursor) { 55 + posts = feed.slice(0, 25); 56 + } else { 57 + let date = cursor.split("::")[0]; 58 + let uri = cursor.split("::")[1]; 59 + posts = feed 60 + .filter((p) => { 61 + if (!p.documents?.data) return false; 62 + let record = p.documents.data as PubLeafletDocument.Record; 63 + if (!record.publishedAt) return false; 64 + return record.publishedAt <= date && uri !== p.documents?.uri; 65 + }) 66 + .slice(0, 25); 67 + } 68 + 69 + let lastPost = posts[posts.length - 1]; 70 + let lastRecord = lastPost?.documents?.data! as PubLeafletDocument.Record; 71 + let newCursor = lastRecord 72 + ? `${lastRecord.publishedAt}::${lastPost.documents?.uri}` 73 + : null; 74 + return c.json({ 75 + cursor: newCursor || cursor, 76 + feed: posts.flatMap((p) => { 52 77 if (!p.documents?.data) return []; 53 78 let record = p.documents.data as PubLeafletDocument.Record; 54 79 if (!record.postRef) return []; 55 80 return { post: record.postRef.uri }; 56 - }); 57 - return c.json({ 58 - feed, 81 + }), 59 82 }); 60 83 }); 61 84