diff options
Diffstat (limited to 'src/lib/link-meta/bsky.ts')
-rw-r--r-- | src/lib/link-meta/bsky.ts | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/src/lib/link-meta/bsky.ts b/src/lib/link-meta/bsky.ts index b052ed04b..322b02332 100644 --- a/src/lib/link-meta/bsky.ts +++ b/src/lib/link-meta/bsky.ts @@ -1,10 +1,10 @@ +import {AppBskyFeedPost, BskyAgent} from '@atproto/api' import * as apilib from 'lib/api/index' import {LikelyType, LinkMeta} from './link-meta' // import {match as matchRoute} from 'view/routes' import {convertBskyAppUrlIfNeeded, makeRecordUri} from '../strings/url-helpers' -import {RootStoreModel} from 'state/index' -import {PostThreadModel} from 'state/models/content/post-thread' -import {ComposerOptsQuote} from 'state/models/ui/shell' +import {ComposerOptsQuote} from 'state/shell/composer' +import {useGetPost} from '#/state/queries/post' // TODO // import {Home} from 'view/screens/Home' @@ -22,7 +22,7 @@ import {ComposerOptsQuote} from 'state/models/ui/shell' // remove once that's implemented // -prf export async function extractBskyMeta( - store: RootStoreModel, + agent: BskyAgent, url: string, ): Promise<LinkMeta> { url = convertBskyAppUrlIfNeeded(url) @@ -102,38 +102,30 @@ export async function extractBskyMeta( } export async function getPostAsQuote( - store: RootStoreModel, + getPost: ReturnType<typeof useGetPost>, url: string, ): Promise<ComposerOptsQuote> { url = convertBskyAppUrlIfNeeded(url) const [_0, user, _1, rkey] = url.split('/').filter(Boolean) - const threadUri = makeRecordUri(user, 'app.bsky.feed.post', rkey) - - const threadView = new PostThreadModel(store, { - uri: threadUri, - depth: 0, - }) - await threadView.setup() - if (!threadView.thread || threadView.notFound) { - throw new Error('Not found') - } + const uri = makeRecordUri(user, 'app.bsky.feed.post', rkey) + const post = await getPost({uri: uri}) return { - uri: threadView.thread.post.uri, - cid: threadView.thread.post.cid, - text: threadView.thread.postRecord?.text || '', - indexedAt: threadView.thread.post.indexedAt, - author: threadView.thread.post.author, + uri: post.uri, + cid: post.cid, + text: AppBskyFeedPost.isRecord(post.record) ? post.record.text : '', + indexedAt: post.indexedAt, + author: post.author, } } export async function getFeedAsEmbed( - store: RootStoreModel, + agent: BskyAgent, 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 res = await store.agent.app.bsky.feed.getFeedGenerator({feed}) + const res = await agent.app.bsky.feed.getFeedGenerator({feed}) return { isLoading: false, uri: feed, @@ -153,13 +145,13 @@ export async function getFeedAsEmbed( } export async function getListAsEmbed( - store: RootStoreModel, + agent: BskyAgent, 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 res = await store.agent.app.bsky.graph.getList({list}) + const res = await agent.app.bsky.graph.getList({list}) return { isLoading: false, uri: list, |