an attempt to make a lightweight, easily self-hostable, scoped bluesky appview
at main 124 lines 4.3 kB view raw
1import { Database } from "jsr:@db/sqlite@0.11"; 2import { config } from "../config.ts"; 3import { parseAtUri } from "../utils/aturi.ts"; 4import { resolveRecordFromURI } from "../utils/records.ts"; 5import { SpacedustManager } from "../utils/sharders.ts"; 6 7export function startSpacedust(spacedustManager: SpacedustManager) { 8 spacedustManager.start({ 9 wantedSources: [ 10 "app.bsky.feed.like:subject.uri", // like 11 "app.bsky.feed.like:via.uri", // liked repost 12 "app.bsky.feed.repost:subject.uri", // repost 13 "app.bsky.feed.repost:via.uri", // reposted repost 14 "app.bsky.feed.post:reply.root.uri", // thread OP 15 "app.bsky.feed.post:reply.parent.uri", // direct parent 16 "app.bsky.feed.post:embed.media.record.record.uri", // quote with media 17 "app.bsky.feed.post:embed.record.uri", // quote without media 18 "app.bsky.feed.threadgate:post", // threadgate subject 19 "app.bsky.feed.threadgate:hiddenReplies", // threadgate items (array) 20 "app.bsky.feed.post:facets.features.did", // facet item (array): mention 21 "app.bsky.graph.block:subject", // blocks 22 "app.bsky.graph.follow:subject", // follow 23 "app.bsky.graph.listblock:subject", // list item (blocks) 24 "app.bsky.graph.listblock:list", // blocklist mention (might not exist) 25 "app.bsky.graph.listitem:subject", // list item (blocks) 26 "app.bsky.graph.listitem:list", // list mention 27 ], 28 // should be getting from DB but whatever right 29 wantedSubjects: [ 30 // as noted i dont need to write down each post, just the user to listen to ! 31 // hell yeah 32 // "at://did:plc:mn45tewwnse5btfftvd3powc/app.bsky.feed.post/3lvybv7b6ic2h", 33 // "at://did:plc:mn45tewwnse5btfftvd3powc/app.bsky.feed.post/3lvybws4avc2h", 34 // "at://did:plc:mn45tewwnse5btfftvd3powc/app.bsky.feed.post/3lvvkcxcscs2h", 35 // "at://did:plc:yy6kbriyxtimkjqonqatv2rb/app.bsky.feed.post/3l63ogxocq42f", 36 // "at://did:plc:yy6kbriyxtimkjqonqatv2rb/app.bsky.feed.post/3lw3wamvflu23", 37 ], 38 wantedSubjectDids: [ 39 "did:plc:mn45tewwnse5btfftvd3powc", 40 "did:plc:yy6kbriyxtimkjqonqatv2rb", 41 "did:plc:zzhzjga3ab5fcs2vnsv2ist3", 42 "did:plc:jz4ibztn56hygfld6j6zjszg", 43 ], // this would be all users in the instance to listen for all remote mentions 44 instant: ["true"] 45 // future question for managing this specifically for like remote content tracking (followed users? items that appears in custom feeds?) 46 }); 47} 48export type SpacedustLinkMessage = { 49 kind: "link"; 50 origin: "live" | string; 51 link: { 52 operation: "create" | "update" | "delete"; 53 source: string; 54 source_record: string; 55 source_rev: string; 56 subject: string; 57 }; 58}; 59 60export async function handleSpacedust(db: Database, msg: SpacedustLinkMessage) { 61 if (!msg || !msg.link || !msg.link.source_record) return; 62 console.log("Received Spacedust message: ", msg); 63 64 const op = msg.link.operation; 65 const srcdid = parseAtUri(msg.link.source_record)?.did; 66 const srccol = parseAtUri(msg.link.source_record)?.collection; 67 if (!srcdid || !srccol) return; 68 const subject = msg.link.subject; 69 const subdid = parseAtUri(subject)?.did; 70 const subscol = parseAtUri(subject)?.collection; 71 if (!subdid || !subscol) return; 72 //const rev = msg.link.source_rev; 73 const aturi = msg.link.source_record; 74 //const value = await resolveRecordFromURI({uri: msg.link.source_record}); 75 db.exec(` 76 INSERT INTO backlink_skeleton ( 77 srcuri, 78 srcdid, 79 srcfield, 80 srccol, 81 suburi, 82 subdid, 83 subcol, 84 indexedAt 85 ) VALUES ( 86 '${aturi}', 87 '${srcdid}', 88 '${srccol}', 89 '${msg.link.source}', 90 '${subject}', 91 '${subdid}', 92 '${subscol}', 93 '${Date.now()}' 94 ); 95 `); 96 //if (!value) return; 97 98 // handleIndex({ 99 // op, 100 // doer, 101 // rev, 102 // aturi, 103 // value, 104 // indexsrc: "spacedust", 105 // }) 106 return; 107 108 // switch (msg.link.source) { 109 // case "app.bsky.feed.like:subject.uri": 110 // switch (op) { 111 // case "create": 112 // // idk 113 // return; 114 // case "update": 115 // // whatever 116 // return; 117 // case "delete": 118 // // lmao 119 // return; 120 // } 121 // } 122 123 124}