Wait for AppView when posting (#4584)

zio/stable
dan 2024-06-21 00:54:30 +03:00 committed by GitHub
parent 51f5e6bf90
commit 5d98b4b06c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 34 additions and 0 deletions

View File

@ -24,12 +24,18 @@ import Animated, {
} from 'react-native-reanimated'
import {useSafeAreaInsets} from 'react-native-safe-area-context'
import {LinearGradient} from 'expo-linear-gradient'
import {
AppBskyFeedDefs,
AppBskyFeedGetPostThread,
BskyAgent,
} from '@atproto/api'
import {RichText} from '@atproto/api'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {observer} from 'mobx-react-lite'
import {until} from '#/lib/async/until'
import {
createGIFDescription,
parseAltFromGIFDescription,
@ -299,6 +305,17 @@ export const ComposePost = observer(function ComposePost({
langs: toPostLanguages(langPrefs.postLanguage),
})
).uri
try {
await whenAppViewReady(agent, postUri, res => {
const thread = res.data.thread
return AppBskyFeedDefs.isThreadViewPost(thread)
})
} catch (waitErr: any) {
logger.error(waitErr, {
message: `Waiting for app view failed`,
})
// Keep going because the post *was* published.
}
} catch (e: any) {
logger.error(e, {
message: `Composer: create post failed`,
@ -756,6 +773,23 @@ function useKeyboardVerticalOffset() {
return top + 10
}
async function whenAppViewReady(
agent: BskyAgent,
uri: string,
fn: (res: AppBskyFeedGetPostThread.Response) => boolean,
) {
await until(
5, // 5 tries
1e3, // 1s delay between tries
fn,
() =>
agent.app.bsky.feed.getPostThread({
uri,
depth: 0,
}),
)
}
const styles = StyleSheet.create({
topbarInner: {
flexDirection: 'row',