Add in new optimistic insert logic

This commit is contained in:
Eric Bailey
2025-05-17 14:19:06 -07:00
parent 5f586cbec0
commit 03b5ef162c
5 changed files with 87 additions and 13 deletions
+4 -4
View File
@@ -407,15 +407,15 @@ export const ComposePost = ({
posts = await retry(5, _e => true, async () => {
const res = await agent.app.bsky.unspecced.getPostThreadV2({
uri: postUri!,
above: 0,
above: 1,
below: thread.posts.length - 1,
branchingFactor: 1,
})
if (res.data.thread.length !== thread.posts.length) {
const parent = res.data.thread.at(0)
if (!AppBskyUnspeccedDefs.isThreadItemPost(parent)) {
throw new Error(`Not ready`)
}
const anchor = res.data.thread.at(0)
if (!AppBskyUnspeccedDefs.isThreadItemPost(anchor)) {
if (res.data.thread.length !== thread.posts.length + 1) {
throw new Error(`Not ready`)
}
return res.data.thread
+6 -2
View File
@@ -161,8 +161,12 @@ export function Inner({uri}: {uri: string | undefined}) {
({post}: {post: AppBskyUnspeccedDefs.ThreadItemPost}) =>
(_: any, posts: AppBskyUnspeccedDefs.ThreadItemPost[]) => {
if (posts.length) {
// TODO get parent and update reply count?
insertReplies(post.uri, posts)
console.log('insert', posts)
const parent = posts.at(0)
const replies = posts.slice(1)
if (parent && replies.length) {
insertReplies(parent, replies)
}
}
}