a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

optimistically update document when bsky post is published

+19 -11
+1 -1
app/[leaflet_id]/publish/PublishPost.tsx
··· 72 72 title: props.title, 73 73 url: post_url, 74 74 description: props.description, 75 - record: doc.record, 75 + document_record: doc.record, 76 76 rkey: doc.rkey, 77 77 }); 78 78 setIsLoading(false);
+18 -10
app/[leaflet_id]/publish/publishBskyPost.ts
··· 6 6 import { getIdentityData } from "actions/getIdentityData"; 7 7 import { AtpBaseClient, PubLeafletDocument } from "lexicons/api"; 8 8 import { createOauthClient } from "src/atproto-oauth"; 9 + import { supabaseServerClient } from "supabase/serverClient"; 10 + import { Json } from "supabase/database.types"; 9 11 10 - export async function publishPostToBsky(bskyPost: { 12 + export async function publishPostToBsky(args: { 11 13 text: string; 12 14 url: string; 13 15 title: string; 14 16 description: string; 15 - record: PubLeafletDocument.Record; 17 + document_record: PubLeafletDocument.Record; 16 18 rkey: string; 17 19 }) { 18 20 const oauthClient = await createOauthClient(); ··· 23 25 let agent = new AtpBaseClient( 24 26 credentialSession.fetchHandler.bind(credentialSession), 25 27 ); 26 - let newPostUrl = bskyPost.url; 28 + let newPostUrl = args.url; 27 29 let preview_image = await fetch( 28 30 `https://pro.microlink.io/?url=${newPostUrl}&screenshot=true&viewport.width=1400&viewport.height=733&meta=false&embed=screenshot.url&force=true`, 29 31 { ··· 51 53 rkey: TID.nextStr(), 52 54 }, 53 55 { 54 - text: bskyPost.text, 56 + text: args.text, 55 57 createdAt: new Date().toISOString(), 56 58 embed: { 57 59 $type: "app.bsky.embed.external", 58 60 external: { 59 - uri: bskyPost.url, 60 - title: bskyPost.title, 61 - description: bskyPost.description, 61 + uri: args.url, 62 + title: args.title, 63 + description: args.description, 62 64 thumb: blob.data.blob, 63 65 }, 64 66 }, 65 67 }, 66 68 ); 67 - let record = bskyPost.record; 69 + let record = args.document_record; 68 70 record.postRef = post; 69 71 70 72 let { data: result } = await agent.com.atproto.repo.putRecord({ 71 - rkey: bskyPost.rkey, 73 + rkey: args.rkey, 72 74 repo: credentialSession.did!, 73 - collection: bskyPost.record.$type, 75 + collection: args.document_record.$type, 74 76 record, 75 77 validate: false, //TODO publish the lexicon so we can validate! 76 78 }); 79 + await supabaseServerClient 80 + .from("documents") 81 + .update({ 82 + data: record as Json, 83 + }) 84 + .eq("uri", result.uri); 77 85 return true; 78 86 }