fix: resolve handle in feed/list urls (#2497)
parent
439f459cef
commit
6076b8f730
|
@ -5,6 +5,7 @@ import {LikelyType, LinkMeta} from './link-meta'
|
||||||
import {convertBskyAppUrlIfNeeded, makeRecordUri} from '../strings/url-helpers'
|
import {convertBskyAppUrlIfNeeded, makeRecordUri} from '../strings/url-helpers'
|
||||||
import {ComposerOptsQuote} from 'state/shell/composer'
|
import {ComposerOptsQuote} from 'state/shell/composer'
|
||||||
import {useGetPost} from '#/state/queries/post'
|
import {useGetPost} from '#/state/queries/post'
|
||||||
|
import {useFetchDid} from '#/state/queries/handle'
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// import {Home} from 'view/screens/Home'
|
// import {Home} from 'view/screens/Home'
|
||||||
|
@ -120,11 +121,13 @@ export async function getPostAsQuote(
|
||||||
|
|
||||||
export async function getFeedAsEmbed(
|
export async function getFeedAsEmbed(
|
||||||
agent: BskyAgent,
|
agent: BskyAgent,
|
||||||
|
fetchDid: ReturnType<typeof useFetchDid>,
|
||||||
url: string,
|
url: string,
|
||||||
): Promise<apilib.ExternalEmbedDraft> {
|
): Promise<apilib.ExternalEmbedDraft> {
|
||||||
url = convertBskyAppUrlIfNeeded(url)
|
url = convertBskyAppUrlIfNeeded(url)
|
||||||
const [_0, user, _1, rkey] = url.split('/').filter(Boolean)
|
const [_0, handleOrDid, _1, rkey] = url.split('/').filter(Boolean)
|
||||||
const feed = makeRecordUri(user, 'app.bsky.feed.generator', rkey)
|
const did = await fetchDid(handleOrDid)
|
||||||
|
const feed = makeRecordUri(did, 'app.bsky.feed.generator', rkey)
|
||||||
const res = await agent.app.bsky.feed.getFeedGenerator({feed})
|
const res = await agent.app.bsky.feed.getFeedGenerator({feed})
|
||||||
return {
|
return {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
@ -146,11 +149,13 @@ export async function getFeedAsEmbed(
|
||||||
|
|
||||||
export async function getListAsEmbed(
|
export async function getListAsEmbed(
|
||||||
agent: BskyAgent,
|
agent: BskyAgent,
|
||||||
|
fetchDid: ReturnType<typeof useFetchDid>,
|
||||||
url: string,
|
url: string,
|
||||||
): Promise<apilib.ExternalEmbedDraft> {
|
): Promise<apilib.ExternalEmbedDraft> {
|
||||||
url = convertBskyAppUrlIfNeeded(url)
|
url = convertBskyAppUrlIfNeeded(url)
|
||||||
const [_0, user, _1, rkey] = url.split('/').filter(Boolean)
|
const [_0, handleOrDid, _1, rkey] = url.split('/').filter(Boolean)
|
||||||
const list = makeRecordUri(user, 'app.bsky.graph.list', rkey)
|
const did = await fetchDid(handleOrDid)
|
||||||
|
const list = makeRecordUri(did, 'app.bsky.graph.list', rkey)
|
||||||
const res = await agent.app.bsky.graph.getList({list})
|
const res = await agent.app.bsky.graph.getList({list})
|
||||||
return {
|
return {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {POST_IMG_MAX} from 'lib/constants'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {getAgent} from '#/state/session'
|
import {getAgent} from '#/state/session'
|
||||||
import {useGetPost} from '#/state/queries/post'
|
import {useGetPost} from '#/state/queries/post'
|
||||||
|
import {useFetchDid} from '#/state/queries/handle'
|
||||||
|
|
||||||
export function useExternalLinkFetch({
|
export function useExternalLinkFetch({
|
||||||
setQuote,
|
setQuote,
|
||||||
|
@ -28,6 +29,7 @@ export function useExternalLinkFetch({
|
||||||
undefined,
|
undefined,
|
||||||
)
|
)
|
||||||
const getPost = useGetPost()
|
const getPost = useGetPost()
|
||||||
|
const fetchDid = useFetchDid()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let aborted = false
|
let aborted = false
|
||||||
|
@ -55,7 +57,7 @@ export function useExternalLinkFetch({
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else if (isBskyCustomFeedUrl(extLink.uri)) {
|
} else if (isBskyCustomFeedUrl(extLink.uri)) {
|
||||||
getFeedAsEmbed(getAgent(), extLink.uri).then(
|
getFeedAsEmbed(getAgent(), fetchDid, extLink.uri).then(
|
||||||
({embed, meta}) => {
|
({embed, meta}) => {
|
||||||
if (aborted) {
|
if (aborted) {
|
||||||
return
|
return
|
||||||
|
@ -73,7 +75,7 @@ export function useExternalLinkFetch({
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else if (isBskyListUrl(extLink.uri)) {
|
} else if (isBskyListUrl(extLink.uri)) {
|
||||||
getListAsEmbed(getAgent(), extLink.uri).then(
|
getListAsEmbed(getAgent(), fetchDid, extLink.uri).then(
|
||||||
({embed, meta}) => {
|
({embed, meta}) => {
|
||||||
if (aborted) {
|
if (aborted) {
|
||||||
return
|
return
|
||||||
|
@ -133,7 +135,7 @@ export function useExternalLinkFetch({
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return cleanup
|
return cleanup
|
||||||
}, [extLink, setQuote, getPost])
|
}, [extLink, setQuote, getPost, fetchDid])
|
||||||
|
|
||||||
return {extLink, setExtLink}
|
return {extLink, setExtLink}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue