about summary refs log tree commit diff
path: root/src/lib/link-meta
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/link-meta')
-rw-r--r--src/lib/link-meta/bsky.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lib/link-meta/bsky.ts b/src/lib/link-meta/bsky.ts
index fba41260d..c9c2ed31a 100644
--- a/src/lib/link-meta/bsky.ts
+++ b/src/lib/link-meta/bsky.ts
@@ -3,6 +3,7 @@ import {match as matchRoute} from 'view/routes'
 import {convertBskyAppUrlIfNeeded, makeRecordUri} from '../strings/url-helpers'
 import {RootStoreModel} from 'state/index'
 import {PostThreadViewModel} from 'state/models/post-thread-view'
+import {ComposerOptsQuote} from 'state/models/shell-ui'
 
 import {Home} from 'view/screens/Home'
 import {Search} from 'view/screens/Search'
@@ -97,3 +98,32 @@ export async function extractBskyMeta(
 
   return meta
 }
+
+export async function getPostAsQuote(
+  store: RootStoreModel,
+  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 PostThreadViewModel(store, {
+    uri: threadUri,
+    depth: 0,
+  })
+  await threadView.setup()
+  if (!threadView.thread || threadView.notFound) {
+    throw new Error('Not found')
+  }
+  return {
+    uri: threadView.thread.post.uri,
+    cid: threadView.thread.post.cid,
+    text: threadView.thread.postRecord?.text || '',
+    indexedAt: threadView.thread.post.indexedAt,
+    author: {
+      handle: threadView.thread.post.author.handle,
+      displayName: threadView.thread.post.author.displayName,
+      avatar: threadView.thread.post.author.avatar,
+    },
+  }
+}