[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 eb947da8a3a8a7d485ff132b3ff0db4a8baaac19 80 lines 2.0 kB view raw
1import { CID } from "multiformats/cid"; 2import { AtUri, normalizeDatetimeAlways } from "@atp/syntax"; 3import * as lex from "../../../lex/lexicons.ts"; 4import * as Audio from "../../../lex/types/so/sprk/sound/audio.ts"; 5import { BackgroundQueue } from "../../background.ts"; 6import { Database } from "../../db/index.ts"; 7import { AudioDocument } from "../../db/models.ts"; 8import { RecordProcessor } from "../processor.ts"; 9 10const lexId = lex.ids.SoSprkSoundAudio; 11type IndexedAudio = AudioDocument; 12 13const insertFn = async ( 14 db: Database, 15 uri: AtUri, 16 cid: CID, 17 obj: Audio.Record, 18 timestamp: string, 19): Promise<IndexedAudio | null> => { 20 const audio: Record<string, unknown> = { 21 uri: uri.toString(), 22 cid: cid.toString(), 23 authorDid: uri.host, 24 sound: obj.sound || null, 25 origin: obj.origin ? { uri: obj.origin.uri, cid: obj.origin.cid } : null, 26 title: obj.title, 27 labels: obj.labels || null, 28 details: obj.details || null, 29 createdAt: normalizeDatetimeAlways(obj.createdAt), 30 indexedAt: timestamp, 31 }; 32 33 // Use findOneAndUpdate with upsert to handle potential duplicate key errors 34 const insertedAudio = await db.models.Audio.findOneAndUpdate( 35 { uri: audio.uri }, 36 { $set: audio }, 37 { upsert: true, new: true }, 38 ); 39 return insertedAudio; 40}; 41 42const findDuplicate = (): AtUri | null => { 43 return null; 44}; 45 46const notifsForInsert = () => { 47 return []; 48}; 49 50const deleteFn = async ( 51 db: Database, 52 uri: AtUri, 53): Promise<IndexedAudio | null> => { 54 const deleted = await db.models.Audio.findOneAndDelete({ 55 uri: uri.toString(), 56 }); 57 return deleted; 58}; 59 60const notifsForDelete = () => { 61 return { notifs: [], toDelete: [] }; 62}; 63 64export type PluginType = RecordProcessor<Audio.Record, IndexedAudio>; 65 66export const makePlugin = ( 67 db: Database, 68 background: BackgroundQueue, 69): PluginType => { 70 return new RecordProcessor(db, background, { 71 lexId, 72 insertFn, 73 findDuplicate, 74 deleteFn, 75 notifsForInsert, 76 notifsForDelete, 77 }); 78}; 79 80export default makePlugin;