WIP RaW
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
|
import {timeout} from '#/lib/async/timeout'
|
||||||
import {isNetworkError} from '#/lib/strings/errors'
|
import {isNetworkError} from '#/lib/strings/errors'
|
||||||
|
|
||||||
export async function retry<P>(
|
export async function retry<P>(
|
||||||
retries: number,
|
retries: number,
|
||||||
cond: (err: any) => boolean,
|
cond: (err: any) => boolean,
|
||||||
fn: () => Promise<P>,
|
fn: () => Promise<P>,
|
||||||
|
delay?: number,
|
||||||
): Promise<P> {
|
): Promise<P> {
|
||||||
let lastErr
|
let lastErr
|
||||||
while (retries > 0) {
|
while (retries > 0) {
|
||||||
@@ -11,7 +13,11 @@ export async function retry<P>(
|
|||||||
return await fn()
|
return await fn()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
lastErr = e
|
lastErr = e
|
||||||
|
// should retry?
|
||||||
if (cond(e)) {
|
if (cond(e)) {
|
||||||
|
if (delay) {
|
||||||
|
await timeout(delay)
|
||||||
|
}
|
||||||
retries--
|
retries--
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import {
|
|||||||
type AppBskyFeedGetPostThread,
|
type AppBskyFeedGetPostThread,
|
||||||
type BskyAgent,
|
type BskyAgent,
|
||||||
type RichText,
|
type RichText,
|
||||||
|
AppBskyFeedGetPostThreadV2,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import {msg, plural, Trans} from '@lingui/macro'
|
import {msg, plural, Trans} from '@lingui/macro'
|
||||||
@@ -56,6 +57,7 @@ import {useQueryClient} from '@tanstack/react-query'
|
|||||||
import * as apilib from '#/lib/api/index'
|
import * as apilib from '#/lib/api/index'
|
||||||
import {EmbeddingDisabledError} from '#/lib/api/resolve'
|
import {EmbeddingDisabledError} from '#/lib/api/resolve'
|
||||||
import {until} from '#/lib/async/until'
|
import {until} from '#/lib/async/until'
|
||||||
|
import {retry} from '#/lib/async/retry'
|
||||||
import {
|
import {
|
||||||
MAX_GRAPHEME_LENGTH,
|
MAX_GRAPHEME_LENGTH,
|
||||||
SUPPORTED_MIME_TYPES,
|
SUPPORTED_MIME_TYPES,
|
||||||
@@ -388,7 +390,8 @@ export const ComposePost = ({
|
|||||||
setError('')
|
setError('')
|
||||||
setIsPublishing(true)
|
setIsPublishing(true)
|
||||||
|
|
||||||
let postUri
|
let postUri: string | undefined
|
||||||
|
let posts: AppBskyFeedGetPostThreadV2.OutputSchema['thread'] = []
|
||||||
try {
|
try {
|
||||||
postUri = (
|
postUri = (
|
||||||
await apilib.post(agent, queryClient, {
|
await apilib.post(agent, queryClient, {
|
||||||
@@ -399,6 +402,20 @@ export const ComposePost = ({
|
|||||||
})
|
})
|
||||||
).uris[0]
|
).uris[0]
|
||||||
try {
|
try {
|
||||||
|
if (postUri) {
|
||||||
|
posts = await retry(5, _e => true, async () => {
|
||||||
|
const res = await agent.app.bsky.feed.getPostThreadV2({
|
||||||
|
uri: postUri!,
|
||||||
|
above: 0,
|
||||||
|
below: thread.posts.length - 1,
|
||||||
|
})
|
||||||
|
if (res.data.thread.length !== thread.posts.length) {
|
||||||
|
throw new Error(`Not ready`)
|
||||||
|
}
|
||||||
|
return res.data.thread
|
||||||
|
}, 1e3)
|
||||||
|
}
|
||||||
|
|
||||||
await whenAppViewReady(agent, postUri, res => {
|
await whenAppViewReady(agent, postUri, res => {
|
||||||
const postedThread = res?.data?.thread
|
const postedThread = res?.data?.thread
|
||||||
return AppBskyFeedDefs.isThreadViewPost(postedThread)
|
return AppBskyFeedDefs.isThreadViewPost(postedThread)
|
||||||
@@ -470,7 +487,7 @@ export const ComposePost = ({
|
|||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
onPost?.(postUri)
|
onPost?.(postUri, posts)
|
||||||
}
|
}
|
||||||
onClose()
|
onClose()
|
||||||
Toast.show(
|
Toast.show(
|
||||||
|
|||||||
@@ -165,6 +165,20 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
[refetch],
|
[refetch],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const optimisticOnPostReply = ({
|
||||||
|
post,
|
||||||
|
}: {
|
||||||
|
post: AppBskyFeedDefs.ThreadItemPost,
|
||||||
|
}) => (_: any, posts: AppBskyFeedDefs.ThreadItemPost[]) => {
|
||||||
|
const parentDepth = post.depth
|
||||||
|
if (posts.length) {
|
||||||
|
for (let i = 0; i < posts.length; i++) {
|
||||||
|
const p = posts[i]
|
||||||
|
p.depth = parentDepth + 1 + i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const {openComposer} = useOpenComposer()
|
const {openComposer} = useOpenComposer()
|
||||||
const onReplyToAnchor = () => {
|
const onReplyToAnchor = () => {
|
||||||
const anchorPost = data?.slices.find(slice => slice.type === 'threadSlice' && slice.ui.isAnchor)
|
const anchorPost = data?.slices.find(slice => slice.type === 'threadSlice' && slice.ui.isAnchor)
|
||||||
@@ -181,7 +195,7 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
embed: post.embed,
|
embed: post.embed,
|
||||||
moderation: anchorPost.moderation,
|
moderation: anchorPost.moderation,
|
||||||
},
|
},
|
||||||
onPost: onPostReply,
|
onPost: optimisticOnPostReply({post:anchorPost.slice}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +223,7 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
overrideBlur={
|
overrideBlur={
|
||||||
shownHiddenReplyKinds.has(HiddenReplyKind.Muted) && item.slice.depth > 0
|
shownHiddenReplyKinds.has(HiddenReplyKind.Muted) && item.slice.depth > 0
|
||||||
}
|
}
|
||||||
onPostReply={onPostReply}
|
onPostReply={optimisticOnPostReply({post:item.slice})}
|
||||||
hideTopBorder={index === 0} // && !item.slice.isParentLoading} // TODO
|
hideTopBorder={index === 0} // && !item.slice.isParentLoading} // TODO
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
Reference in New Issue
Block a user