Skip to content

Commit

Permalink
fix: resolve handle in feed/list urls (#2497)
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-ext authored Jan 23, 2024
1 parent 439f459 commit 6076b8f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/lib/link-meta/bsky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {LikelyType, LinkMeta} from './link-meta'
import {convertBskyAppUrlIfNeeded, makeRecordUri} from '../strings/url-helpers'
import {ComposerOptsQuote} from 'state/shell/composer'
import {useGetPost} from '#/state/queries/post'
import {useFetchDid} from '#/state/queries/handle'

// TODO
// import {Home} from 'view/screens/Home'
Expand Down Expand Up @@ -120,11 +121,13 @@ export async function getPostAsQuote(

export async function getFeedAsEmbed(
agent: BskyAgent,
fetchDid: ReturnType<typeof useFetchDid>,
url: string,
): Promise<apilib.ExternalEmbedDraft> {
url = convertBskyAppUrlIfNeeded(url)
const [_0, user, _1, rkey] = url.split('/').filter(Boolean)
const feed = makeRecordUri(user, 'app.bsky.feed.generator', rkey)
const [_0, handleOrDid, _1, rkey] = url.split('/').filter(Boolean)
const did = await fetchDid(handleOrDid)
const feed = makeRecordUri(did, 'app.bsky.feed.generator', rkey)
const res = await agent.app.bsky.feed.getFeedGenerator({feed})
return {
isLoading: false,
Expand All @@ -146,11 +149,13 @@ export async function getFeedAsEmbed(

export async function getListAsEmbed(
agent: BskyAgent,
fetchDid: ReturnType<typeof useFetchDid>,
url: string,
): Promise<apilib.ExternalEmbedDraft> {
url = convertBskyAppUrlIfNeeded(url)
const [_0, user, _1, rkey] = url.split('/').filter(Boolean)
const list = makeRecordUri(user, 'app.bsky.graph.list', rkey)
const [_0, handleOrDid, _1, rkey] = url.split('/').filter(Boolean)
const did = await fetchDid(handleOrDid)
const list = makeRecordUri(did, 'app.bsky.graph.list', rkey)
const res = await agent.app.bsky.graph.getList({list})
return {
isLoading: false,
Expand Down
8 changes: 5 additions & 3 deletions src/view/com/composer/useExternalLinkFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {POST_IMG_MAX} from 'lib/constants'
import {logger} from '#/logger'
import {getAgent} from '#/state/session'
import {useGetPost} from '#/state/queries/post'
import {useFetchDid} from '#/state/queries/handle'

export function useExternalLinkFetch({
setQuote,
Expand All @@ -28,6 +29,7 @@ export function useExternalLinkFetch({
undefined,
)
const getPost = useGetPost()
const fetchDid = useFetchDid()

useEffect(() => {
let aborted = false
Expand Down Expand Up @@ -55,7 +57,7 @@ export function useExternalLinkFetch({
},
)
} else if (isBskyCustomFeedUrl(extLink.uri)) {
getFeedAsEmbed(getAgent(), extLink.uri).then(
getFeedAsEmbed(getAgent(), fetchDid, extLink.uri).then(
({embed, meta}) => {
if (aborted) {
return
Expand All @@ -73,7 +75,7 @@ export function useExternalLinkFetch({
},
)
} else if (isBskyListUrl(extLink.uri)) {
getListAsEmbed(getAgent(), extLink.uri).then(
getListAsEmbed(getAgent(), fetchDid, extLink.uri).then(
({embed, meta}) => {
if (aborted) {
return
Expand Down Expand Up @@ -133,7 +135,7 @@ export function useExternalLinkFetch({
})
}
return cleanup
}, [extLink, setQuote, getPost])
}, [extLink, setQuote, getPost, fetchDid])

return {extLink, setExtLink}
}

0 comments on commit 6076b8f

Please sign in to comment.