diff options
Diffstat (limited to 'src/view/com/composer/Composer.tsx')
-rw-r--r-- | src/view/com/composer/Composer.tsx | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 7336f3b95..d8af6d0ce 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -14,7 +14,7 @@ import { import {useSafeAreaInsets} from 'react-native-safe-area-context' import LinearGradient from 'react-native-linear-gradient' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' -import {RichText} from '@atproto/api' +import {AppBskyFeedGetPosts, RichText} from '@atproto/api' import {useAnalytics} from 'lib/analytics/analytics' import {useIsKeyboardVisible} from 'lib/hooks/useIsKeyboardVisible' import {ExternalEmbed} from './ExternalEmbed' @@ -59,6 +59,8 @@ import { import {useSession, getAgent} from '#/state/session' import {useProfileQuery} from '#/state/queries/profile' import {useComposerControls} from '#/state/shell/composer' +import {until} from '#/lib/async/until' +import {emitPostCreated} from '#/state/events' type Props = ComposerOpts export const ComposePost = observer(function ComposePost({ @@ -208,17 +210,20 @@ export const ComposePost = observer(function ComposePost({ setIsProcessing(true) + let postUri try { - await apilib.post(getAgent(), { - rawText: richtext.text, - replyTo: replyTo?.uri, - images: gallery.images, - quote, - extLink, - labels, - onStateChange: setProcessingState, - langs: toPostLanguages(langPrefs.postLanguage), - }) + postUri = ( + await apilib.post(getAgent(), { + rawText: richtext.text, + replyTo: replyTo?.uri, + images: gallery.images, + quote, + extLink, + labels, + onStateChange: setProcessingState, + langs: toPostLanguages(langPrefs.postLanguage), + }) + ).uri } catch (e: any) { if (extLink) { setExtLink({ @@ -236,8 +241,10 @@ export const ComposePost = observer(function ComposePost({ }) if (replyTo && replyTo.uri) track('Post:Reply') } - if (!replyTo) { - // TODO onPostCreated + if (postUri && !replyTo) { + whenAppViewReady(postUri).then(() => { + emitPostCreated() + }) } setLangPrefs.savePostLanguageToHistory() onPost?.() @@ -533,3 +540,15 @@ const styles = StyleSheet.create({ borderTopWidth: 1, }, }) + +async function whenAppViewReady(uri: string) { + await until( + 5, // 5 tries + 1e3, // 1s delay between tries + (res: AppBskyFeedGetPosts.Response) => !!res.data.posts[0], + () => + getAgent().getPosts({ + uris: [uri], + }), + ) +} |