my monorepo for atproto based applications

feed for comments and top posts

+40
+36
feed-generator/src/algos/heb-ppl-posts-comments.ts
··· 1 + import { QueryParams } from "@my/lexicon/server/types/app/bsky/feed/getFeedSkeleton"; 2 + import { AppContext } from "@/config"; 3 + 4 + // max 15 chars 5 + export const shortname = "heb-ppl-pst-cmt"; 6 + 7 + export const handler = async (ctx: AppContext, params: QueryParams) => { 8 + let builder = ctx.db 9 + .selectFrom("post") 10 + .selectAll() 11 + .orderBy("indexedAt", "desc") 12 + .orderBy("cid", "desc") 13 + // .where("parent_cid", "is not", null) // this is what makes it only posts and not replies 14 + .limit(params.limit); 15 + 16 + if (params.cursor) { 17 + const timeStr = new Date(parseInt(params.cursor, 10)).toISOString(); 18 + builder = builder.where("post.indexedAt", "<", timeStr); 19 + } 20 + const res = await builder.execute(); 21 + 22 + const feed = res.map((row) => ({ 23 + post: row.uri, 24 + })); 25 + 26 + let cursor: string | undefined; 27 + const last = res.at(-1); 28 + if (last) { 29 + cursor = new Date(last.indexedAt).getTime().toString(10); 30 + } 31 + 32 + return { 33 + cursor, 34 + feed, 35 + }; 36 + };
+1
feed-generator/src/algos/heb-ppl-posts.ts
··· 10 10 .selectAll() 11 11 .orderBy("indexedAt", "desc") 12 12 .orderBy("cid", "desc") 13 + .where("parent_cid", "is not", null) // this is what makes it only posts and not replies 13 14 .limit(params.limit); 14 15 15 16 if (params.cursor) {
+1
feed-generator/src/db/migrations.ts
··· 15 15 .addColumn("uri", "varchar", (col) => col.primaryKey()) 16 16 .addColumn("cid", "varchar", (col) => col.notNull()) 17 17 .addColumn("author_did", "varchar", (col) => col.notNull()) 18 + .addColumn("parent_cid", "varchar") 18 19 .addColumn("indexedAt", "varchar", (col) => col.notNull()) 19 20 .addColumn("analysis", "text") // json 20 21 .execute();
+1
feed-generator/src/db/schema.ts
··· 8 8 uri: string; 9 9 cid: string; 10 10 author_did: string; 11 + parent_cid?: string | null; 11 12 indexedAt: string; 12 13 analysis: string; 13 14 };
+1
feed-generator/src/heb-ppl/subscriber.ts
··· 94 94 uri: post.uri, 95 95 cid: post.cid, 96 96 author_did: post.author, 97 + parent_cid: post.record.reply?.parent.cid, 97 98 indexedAt: timestamp, 98 99 analysis: JSON.stringify({ counts }), 99 100 };