[READ ONLY MIRROR] Spark Social AppView Server github.com/sprksocial/server
atproto deno hono lexicon
5
fork

Configure Feed

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

added following feed generator

honys c26ebba9 440157f2

+43
+43
services/feed-gen/src/algos/following.ts
··· 1 + import { Database } from '../db/connection'; 2 + 3 + export const shortname = 'following' 4 + 5 + export const handler = async (db: Database, params: any) => { 6 + const { limit = 50, userDid, cursor } = params; 7 + 8 + // Build the query 9 + const query: any = {}; 10 + 11 + // Apply cursor if provided 12 + if (cursor) { 13 + const timestamp = new Date(parseInt(cursor, 10)); 14 + query.indexedAt = { $lt: timestamp }; 15 + } 16 + 17 + const followers = (await db.models.Follow.find( 18 + { authorDid: userDid } 19 + )).map((follow) => follow.subject) 20 + 21 + // Get posts from MongoDB, sorted by most recent 22 + const posts = await db.models.Post.find(query) 23 + .sort({ indexedAt: -1 }) 24 + .where('authorDid').in(followers) 25 + .limit(limit) 26 + 27 + // Map to feed format 28 + const feed = posts.map((post) => ({ 29 + post: post.uri 30 + })); 31 + 32 + // Set cursor for pagination 33 + let nextCursor: string | undefined; 34 + const lastPost = posts.at(-1); 35 + if (lastPost) { 36 + nextCursor = new Date(lastPost.indexedAt).getTime().toString(10); 37 + } 38 + 39 + return { 40 + cursor: nextCursor, 41 + feed, 42 + }; 43 + }