Fix reply failures caused by fetching posts from PDS (#9925)
This commit is contained in:
+34
-14
@@ -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(
|
||||
|
||||
@@ -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.`
|
||||
|
||||
Reference in New Issue
Block a user