data endpoint for entity 90008 (aka. a website)
0
fork

Configure Feed

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

fix: post using reply with parent post

dusk a3d79509 7440f613

+12 -20
+12 -20
src/routes/log/create/+server.ts
··· 2 2 import { PUBLIC_BASE_URL } from '$env/static/public'; 3 3 import { getBskyClient } from '$lib/bluesky.js'; 4 4 import { createNote, findReplyRoot, genNoteId, readNote, type Note } from '$lib/notes'; 5 - import type { Post, ReplyRef } from '@skyware/bot'; 5 + import type { Post, PostPayload, PostReference, ReplyRef } from '@skyware/bot'; 6 6 7 7 interface NoteData { 8 8 content: string, ··· 38 38 const postContent = `${noteData.content} (${PUBLIC_BASE_URL}/log?id=${noteId})` 39 39 try { 40 40 const bot = await getBskyClient() 41 + let postPayload: PostPayload = { 42 + text: postContent, 43 + createdAt: new Date(note.published), 44 + external: noteData.embedUri, 45 + } 46 + let postRef: PostReference 41 47 // find parent and reply posts 42 48 let replyRef: ReplyRef | null = null 43 49 if (noteData.replyTo !== undefined && repliedNote !== null) { 44 50 const getBskyUri = (note: Note) => { return note.outgoingLinks?.find((v) => {return v.name === "bsky"})?.link } 45 51 const parentUri = getBskyUri(repliedNote) 46 - let parentPost: Post | null = null 47 52 if (parentUri !== undefined) { 48 - parentPost = await bot.getPost(parentUri) 49 - } 50 - const rootUri = getBskyUri(findReplyRoot(noteData.replyTo).rootNote) 51 - let rootPost: Post | null = null 52 - if (rootUri !== undefined) { 53 - rootPost = await bot.getPost(rootUri) 54 - } 55 - if (parentPost !== null && rootPost !== null) { 56 - replyRef = { 57 - parent: parentPost, 58 - root: rootPost, 59 - } 53 + const parentPost = await bot.getPost(parentUri) 54 + postRef = await parentPost.reply(postPayload) 60 55 } 56 + throw "a reply was requested but no reply is found" 57 + } else { 58 + postRef = await bot.post(postPayload) 61 59 } 62 - const postRef = await bot.post({ 63 - text: postContent, 64 - createdAt: new Date(note.published), 65 - replyRef: replyRef ?? undefined, 66 - external: noteData.embedUri, 67 - }) 68 60 note.outgoingLinks?.push({name: "bsky", link: postRef.uri}) 69 61 } catch(why) { 70 62 console.log(`failed to post note #${noteId} to bsky: `, why)