about summary refs log tree commit diff
path: root/src/lib/link-meta
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2023-11-15 19:09:13 -0600
committerGitHub <noreply@github.com>2023-11-15 17:09:13 -0800
commitf23e9978d839322aab7304d2b6f183722e3ad4c1 (patch)
treea21f5e4056182c3f9b3bff6ef16246d4100a23d0 /src/lib/link-meta
parent9bcd00b83174cca3baef0519ba688e403662eea5 (diff)
downloadvoidsky-f23e9978d839322aab7304d2b6f183722e3ad4c1.tar.zst
Update post embed fetching to use new methods (#1916)
* Update post embed fetching to use new methods

* Use session agent
Diffstat (limited to 'src/lib/link-meta')
-rw-r--r--src/lib/link-meta/bsky.ts27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/lib/link-meta/bsky.ts b/src/lib/link-meta/bsky.ts
index 2134c3292..78d755331 100644
--- a/src/lib/link-meta/bsky.ts
+++ b/src/lib/link-meta/bsky.ts
@@ -1,10 +1,11 @@
+import {AppBskyFeedPost} 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/shell/composer'
+import {useGetPost} from '#/state/queries/post'
 
 // TODO
 // import {Home} from 'view/screens/Home'
@@ -102,27 +103,19 @@ 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,
   }
 }