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 AppBskyEmbedRecord,
|
||||||
type AppBskyEmbedRecordWithMedia,
|
type AppBskyEmbedRecordWithMedia,
|
||||||
type AppBskyEmbedVideo,
|
type AppBskyEmbedVideo,
|
||||||
type AppBskyFeedPost,
|
AppBskyFeedPost,
|
||||||
AtUri,
|
|
||||||
BlobRef,
|
BlobRef,
|
||||||
type BskyAgent,
|
type BskyAgent,
|
||||||
type ComAtprotoLabelDefs,
|
type ComAtprotoLabelDefs,
|
||||||
@@ -39,6 +38,7 @@ import {
|
|||||||
type PostDraft,
|
type PostDraft,
|
||||||
type ThreadDraft,
|
type ThreadDraft,
|
||||||
} from '#/view/com/composer/state/composer'
|
} from '#/view/com/composer/state/composer'
|
||||||
|
import * as bsky from '#/types/bsky'
|
||||||
import {createGIFDescription} from '../gif-alt-text'
|
import {createGIFDescription} from '../gif-alt-text'
|
||||||
import {uploadBlob} from './upload-blob'
|
import {uploadBlob} from './upload-blob'
|
||||||
|
|
||||||
@@ -214,22 +214,42 @@ async function resolveRT(agent: BskyAgent, richtext: RichText) {
|
|||||||
return rt
|
return rt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ReplyDeletedError extends Error {
|
||||||
|
constructor() {
|
||||||
|
super('Could not resolve reply')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function resolveReply(agent: BskyAgent, replyTo: string) {
|
async function resolveReply(agent: BskyAgent, replyTo: string) {
|
||||||
const replyToUrip = new AtUri(replyTo)
|
const {data} = await agent.app.bsky.feed.getPosts({
|
||||||
const parentPost = await agent.getPost({
|
uris: [replyTo],
|
||||||
repo: replyToUrip.host,
|
|
||||||
rkey: replyToUrip.rkey,
|
|
||||||
})
|
})
|
||||||
if (parentPost) {
|
const parentPost = data.posts[0]
|
||||||
const parentRef = {
|
if (!parentPost) {
|
||||||
uri: parentPost.uri,
|
throw new ReplyDeletedError()
|
||||||
cid: parentPost.cid,
|
}
|
||||||
}
|
|
||||||
return {
|
const parentRef = {
|
||||||
root: parentPost.value.reply?.root || parentRef,
|
uri: parentPost.uri,
|
||||||
parent: parentRef,
|
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(
|
async function resolveEmbed(
|
||||||
|
|||||||
@@ -948,7 +948,10 @@ export const ComposePost = ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
let err = cleanError(e.message)
|
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.`
|
err = l`We're sorry! The post you are replying to has been deleted.`
|
||||||
} else if (e instanceof EmbeddingDisabledError) {
|
} else if (e instanceof EmbeddingDisabledError) {
|
||||||
err = l`This post's author has disabled quote posts.`
|
err = l`This post's author has disabled quote posts.`
|
||||||
|
|||||||
Reference in New Issue
Block a user