import { Database } from "jsr:@db/sqlite@0.11"; import { config } from "../config.ts"; import { parseAtUri } from "../utils/aturi.ts"; import { resolveRecordFromURI } from "../utils/records.ts"; import { SpacedustManager } from "../utils/sharders.ts"; export function startSpacedust(spacedustManager: SpacedustManager) { spacedustManager.start({ wantedSources: [ "app.bsky.feed.like:subject.uri", // like "app.bsky.feed.like:via.uri", // liked repost "app.bsky.feed.repost:subject.uri", // repost "app.bsky.feed.repost:via.uri", // reposted repost "app.bsky.feed.post:reply.root.uri", // thread OP "app.bsky.feed.post:reply.parent.uri", // direct parent "app.bsky.feed.post:embed.media.record.record.uri", // quote with media "app.bsky.feed.post:embed.record.uri", // quote without media "app.bsky.feed.threadgate:post", // threadgate subject "app.bsky.feed.threadgate:hiddenReplies", // threadgate items (array) "app.bsky.feed.post:facets.features.did", // facet item (array): mention "app.bsky.graph.block:subject", // blocks "app.bsky.graph.follow:subject", // follow "app.bsky.graph.listblock:subject", // list item (blocks) "app.bsky.graph.listblock:list", // blocklist mention (might not exist) "app.bsky.graph.listitem:subject", // list item (blocks) "app.bsky.graph.listitem:list", // list mention ], // should be getting from DB but whatever right wantedSubjects: [ // as noted i dont need to write down each post, just the user to listen to ! // hell yeah // "at://did:plc:mn45tewwnse5btfftvd3powc/app.bsky.feed.post/3lvybv7b6ic2h", // "at://did:plc:mn45tewwnse5btfftvd3powc/app.bsky.feed.post/3lvybws4avc2h", // "at://did:plc:mn45tewwnse5btfftvd3powc/app.bsky.feed.post/3lvvkcxcscs2h", // "at://did:plc:yy6kbriyxtimkjqonqatv2rb/app.bsky.feed.post/3l63ogxocq42f", // "at://did:plc:yy6kbriyxtimkjqonqatv2rb/app.bsky.feed.post/3lw3wamvflu23", ], wantedSubjectDids: [ "did:plc:mn45tewwnse5btfftvd3powc", "did:plc:yy6kbriyxtimkjqonqatv2rb", "did:plc:zzhzjga3ab5fcs2vnsv2ist3", "did:plc:jz4ibztn56hygfld6j6zjszg", ], // this would be all users in the instance to listen for all remote mentions instant: ["true"] // future question for managing this specifically for like remote content tracking (followed users? items that appears in custom feeds?) }); } export type SpacedustLinkMessage = { kind: "link"; origin: "live" | string; link: { operation: "create" | "update" | "delete"; source: string; source_record: string; source_rev: string; subject: string; }; }; export async function handleSpacedust(db: Database, msg: SpacedustLinkMessage) { if (!msg || !msg.link || !msg.link.source_record) return; console.log("Received Spacedust message: ", msg); const op = msg.link.operation; const srcdid = parseAtUri(msg.link.source_record)?.did; const srccol = parseAtUri(msg.link.source_record)?.collection; if (!srcdid || !srccol) return; const subject = msg.link.subject; const subdid = parseAtUri(subject)?.did; const subscol = parseAtUri(subject)?.collection; if (!subdid || !subscol) return; //const rev = msg.link.source_rev; const aturi = msg.link.source_record; //const value = await resolveRecordFromURI({uri: msg.link.source_record}); db.exec(` INSERT INTO backlink_skeleton ( srcuri, srcdid, srcfield, srccol, suburi, subdid, subcol, indexedAt ) VALUES ( '${aturi}', '${srcdid}', '${srccol}', '${msg.link.source}', '${subject}', '${subdid}', '${subscol}', '${Date.now()}' ); `); //if (!value) return; // handleIndex({ // op, // doer, // rev, // aturi, // value, // indexsrc: "spacedust", // }) return; // switch (msg.link.source) { // case "app.bsky.feed.like:subject.uri": // switch (op) { // case "create": // // idk // return; // case "update": // // whatever // return; // case "delete": // // lmao // return; // } // } }