[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.

at main 76 lines 1.8 kB view raw
1import { Cid } from "@atp/lex"; 2import { AtUri, normalizeDatetimeAlways } from "@atp/syntax"; 3import * as so from "../../../lex/so.ts"; 4import { BackgroundQueue } from "../../background.ts"; 5import { Database } from "../../db/index.ts"; 6import { LabelerDocument } from "../../db/models.ts"; 7import { RecordProcessor } from "../processor.ts"; 8 9const schema = so.sprk.labeler.service.main; 10type LabelerRecord = so.sprk.labeler.service.Main; 11type IndexedLabeler = LabelerDocument; 12 13const insertFn = async ( 14 db: Database, 15 uri: AtUri, 16 cid: Cid, 17 obj: LabelerRecord, 18 timestamp: string, 19): Promise<IndexedLabeler | null> => { 20 if (uri.rkey !== "self") return null; 21 22 const labeler = { 23 uri: uri.toString(), 24 cid: cid.toString(), 25 authorDid: uri.host, 26 createdAt: normalizeDatetimeAlways(obj.createdAt), 27 indexedAt: timestamp, 28 }; 29 30 const insertedLabeler = await db.models.Labeler.findOneAndUpdate( 31 { uri: labeler.uri }, 32 { $set: labeler }, 33 { upsert: true, returnDocument: "after" }, 34 ); 35 return insertedLabeler; 36}; 37 38const findDuplicate = (): AtUri | null => { 39 return null; 40}; 41 42const notifsForInsert = () => { 43 return []; 44}; 45 46const deleteFn = async ( 47 db: Database, 48 uri: AtUri, 49): Promise<IndexedLabeler | null> => { 50 const deleted = await db.models.Labeler.findOneAndDelete({ 51 uri: uri.toString(), 52 }); 53 return deleted; 54}; 55 56const notifsForDelete = () => { 57 return { notifs: [], toDelete: [] }; 58}; 59 60export type PluginType = RecordProcessor<typeof schema, IndexedLabeler>; 61 62export const makePlugin = ( 63 db: Database, 64 background: BackgroundQueue, 65): PluginType => { 66 return new RecordProcessor(db, background, { 67 schema, 68 insertFn, 69 findDuplicate, 70 deleteFn, 71 notifsForInsert, 72 notifsForDelete, 73 }); 74}; 75 76export default makePlugin;