Fix reply failures caused by fetching posts from PDS (#9925)

This commit is contained in:
Samuel Newman
2026-05-15 19:43:07 +01:00
committed by GitHub
parent e0cb1c3413
commit 9d98890fd2
2 changed files with 38 additions and 15 deletions
+34 -14
View File
@@ -5,8 +5,7 @@ import {
type AppBskyEmbedRecord,
type AppBskyEmbedRecordWithMedia,
type AppBskyEmbedVideo,
type AppBskyFeedPost,
AtUri,
AppBskyFeedPost,
BlobRef,
type BskyAgent,
type ComAtprotoLabelDefs,
@@ -39,6 +38,7 @@ import {
type PostDraft,
type ThreadDraft,
} from '#/view/com/composer/state/composer'
import * as bsky from '#/types/bsky'
import {createGIFDescription} from '../gif-alt-text'
import {uploadBlob} from './upload-blob'
@@ -214,22 +214,42 @@ async function resolveRT(agent: BskyAgent, richtext: RichText) {
return rt
}
export class ReplyDeletedError extends Error {
constructor() {
super('Could not resolve reply')
}
}
async function resolveReply(agent: BskyAgent, replyTo: string) {
const replyToUrip = new AtUri(replyTo)
const parentPost = await agent.getPost({
repo: replyToUrip.host,
rkey: replyToUrip.rkey,
const {data} = await agent.app.bsky.feed.getPosts({
uris: [replyTo],
})
if (parentPost) {
const parentRef = {
uri: parentPost.uri,
cid: parentPost.cid,
}
return {
root: parentPost.value.reply?.root || parentRef,
parent: parentRef,
const parentPost = data.posts[0]
if (!parentPost) {
throw new ReplyDeletedError()
}
const parentRef = {
uri: parentPost.uri,
cid: parentPost.cid,
}
let rootRef = parentRef
if (
bsky.dangerousIsType<AppBskyFeedPost.Record>(
parentPost.record,
AppBskyFeedPost.isRecord,
)
) {
if (parentPost.record.reply) {
rootRef = parentPost.record.reply.root
}
}
return {
root: rootRef,
parent: parentRef,
}
}
async function resolveEmbed(
+4 -1
View File
@@ -948,7 +948,10 @@ export const ComposePost = ({
})
let err = cleanError(e.message)
if (err.includes('not locate record')) {
if (
e instanceof apilib.ReplyDeletedError ||
err.includes('not locate record')
) {
err = l`We're sorry! The post you are replying to has been deleted.`
} else if (e instanceof EmbeddingDisabledError) {
err = l`This post's author has disabled quote posts.`