diff --git a/appview/index.ts b/appview/index.ts index 7be9e892..0bdf2d76 100644 --- a/appview/index.ts +++ b/appview/index.ts @@ -55,6 +55,8 @@ async function main() { ids.SiteStandardDocument, ids.SiteStandardPublication, ids.SiteStandardGraphSubscription, + "parts.page.mention.service", + "parts.page.mention.config", ], handleEvent, onError: (err) => { @@ -370,6 +372,42 @@ async function handleEvent(evt: Event) { // .eq("did", evt.did); // } // } + if (evt.collection === "parts.page.mention.service") { + if (evt.event === "create" || evt.event === "update") { + let record = evt.record as any; + if (!record?.name || !record?.endpoint) return; + let { error } = await supabase.from("mention_services").upsert({ + uri: evt.uri.toString(), + identity_did: evt.did, + record: record as Json, + }); + if (error) console.log("Error upserting mention service:", error); + } + if (evt.event === "delete") { + await supabase + .from("mention_services") + .delete() + .eq("uri", evt.uri.toString()); + } + } + if (evt.collection === "parts.page.mention.config") { + if (evt.event === "create" || evt.event === "update") { + let record = evt.record as any; + if (!Array.isArray(record?.services)) return; + let { error } = await supabase.from("mention_service_configs").upsert({ + uri: evt.uri.toString(), + identity_did: evt.did, + record: record as Json, + }); + if (error) console.log("Error upserting mention config:", error); + } + if (evt.event === "delete") { + await supabase + .from("mention_service_configs") + .delete() + .eq("uri", evt.uri.toString()); + } + } if (evt.collection === "app.bsky.feed.post") { if (evt.event !== "create") return; diff --git a/supabase/database.types.ts b/supabase/database.types.ts index 5701f414..68844690 100644 --- a/supabase/database.types.ts +++ b/supabase/database.types.ts @@ -702,6 +702,42 @@ export type Database = { }, ] } + mention_service_configs: { + Row: { + identity_did: string + record: Json + uri: string + } + Insert: { + identity_did: string + record: Json + uri: string + } + Update: { + identity_did?: string + record?: Json + uri?: string + } + Relationships: [] + } + mention_services: { + Row: { + identity_did: string + record: Json + uri: string + } + Insert: { + identity_did: string + record: Json + uri: string + } + Update: { + identity_did?: string + record?: Json + uri?: string + } + Relationships: [] + } notifications: { Row: { created_at: string diff --git a/supabase/migrations/20260323000000_add_mention_services.sql b/supabase/migrations/20260323000000_add_mention_services.sql new file mode 100644 index 00000000..5dd6ff03 --- /dev/null +++ b/supabase/migrations/20260323000000_add_mention_services.sql @@ -0,0 +1,13 @@ +CREATE TABLE mention_services ( + uri TEXT PRIMARY KEY, + identity_did TEXT NOT NULL, + record JSONB NOT NULL +); +CREATE INDEX idx_mention_services_did ON mention_services(identity_did); + +CREATE TABLE mention_service_configs ( + uri TEXT PRIMARY KEY, + identity_did TEXT NOT NULL UNIQUE, + record JSONB NOT NULL +); +CREATE INDEX idx_mention_service_configs_did ON mention_service_configs(identity_did);