Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update post embed fetching to use new methods (#1916)

* Update post embed fetching to use new methods

* Use session agent

authored by

Eric Bailey and committed by
GitHub
f23e9978 9bcd00b8

+51 -22
+36 -2
src/state/queries/post.ts
··· 1 - import {AppBskyFeedDefs} from '@atproto/api' 2 - import {useQuery, useMutation} from '@tanstack/react-query' 1 + import React from 'react' 2 + import {AppBskyFeedDefs, AtUri} from '@atproto/api' 3 + import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query' 3 4 import {useSession} from '../session' 4 5 import {updatePostShadow} from '../cache/post-shadow' 5 6 ··· 19 20 }, 20 21 enabled: !!uri, 21 22 }) 23 + } 24 + 25 + export function useGetPost() { 26 + const queryClient = useQueryClient() 27 + const {agent} = useSession() 28 + return React.useCallback( 29 + async ({uri}: {uri: string}) => { 30 + return queryClient.fetchQuery({ 31 + queryKey: RQKEY(uri || ''), 32 + async queryFn() { 33 + const urip = new AtUri(uri) 34 + 35 + if (!urip.host.startsWith('did:')) { 36 + const res = await agent.resolveHandle({ 37 + handle: urip.host, 38 + }) 39 + urip.host = res.data.did 40 + } 41 + 42 + const res = await agent.getPosts({ 43 + uris: [urip.toString()!], 44 + }) 45 + 46 + if (res.success && res.data.posts[0]) { 47 + return res.data.posts[0] 48 + } 49 + 50 + throw new Error('useGetPost: post not found') 51 + }, 52 + }) 53 + }, 54 + [agent, queryClient], 55 + ) 22 56 } 23 57 24 58 export function usePostLikeMutation() {
+5 -3
src/view/com/composer/useExternalLinkFetch.ts
··· 17 17 import {ComposerOpts} from 'state/shell/composer' 18 18 import {POST_IMG_MAX} from 'lib/constants' 19 19 import {logger} from '#/logger' 20 + import {useGetPost} from '#/state/queries/post' 20 21 21 22 export function useExternalLinkFetch({ 22 23 setQuote, ··· 27 28 const [extLink, setExtLink] = useState<apilib.ExternalEmbedDraft | undefined>( 28 29 undefined, 29 30 ) 31 + const getPost = useGetPost() 30 32 31 33 useEffect(() => { 32 34 let aborted = false ··· 38 40 } 39 41 if (!extLink.meta) { 40 42 if (isBskyPostUrl(extLink.uri)) { 41 - getPostAsQuote(store, extLink.uri).then( 43 + getPostAsQuote(getPost, extLink.uri).then( 42 44 newQuote => { 43 45 if (aborted) { 44 46 return ··· 48 50 }, 49 51 err => { 50 52 logger.error('Failed to fetch post for quote embedding', { 51 - error: err, 53 + error: err.toString(), 52 54 }) 53 55 setExtLink(undefined) 54 56 }, ··· 132 134 }) 133 135 } 134 136 return cleanup 135 - }, [store, extLink, setQuote]) 137 + }, [store, extLink, setQuote, getPost]) 136 138 137 139 return {extLink, setExtLink} 138 140 }