about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/link-meta/bsky.ts26
-rw-r--r--src/lib/strings/url-helpers.ts14
2 files changed, 40 insertions, 0 deletions
diff --git a/src/lib/link-meta/bsky.ts b/src/lib/link-meta/bsky.ts
index cf43feca8..aed103894 100644
--- a/src/lib/link-meta/bsky.ts
+++ b/src/lib/link-meta/bsky.ts
@@ -155,3 +155,29 @@ export async function getFeedAsEmbed(
     },
   }
 }
+
+export async function getListAsEmbed(
+  store: RootStoreModel,
+  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})
+  return {
+    isLoading: false,
+    uri: list,
+    meta: {
+      url: list,
+      likelyType: LikelyType.AtpData,
+      title: res.data.list.name,
+    },
+    embed: {
+      $type: 'app.bsky.embed.record',
+      record: {
+        uri: res.data.list.uri,
+        cid: res.data.list.cid,
+      },
+    },
+  }
+}
diff --git a/src/lib/strings/url-helpers.ts b/src/lib/strings/url-helpers.ts
index d6d43b89d..ec1292e94 100644
--- a/src/lib/strings/url-helpers.ts
+++ b/src/lib/strings/url-helpers.ts
@@ -94,6 +94,20 @@ export function isBskyCustomFeedUrl(url: string): boolean {
   return false
 }
 
+export function isBskyListUrl(url: string): boolean {
+  if (isBskyAppUrl(url)) {
+    try {
+      const urlp = new URL(url)
+      return /profile\/(?<name>[^/]+)\/lists\/(?<rkey>[^/]+)/i.test(
+        urlp.pathname,
+      )
+    } catch {
+      console.error('Unexpected error in isBskyListUrl()', url)
+    }
+  }
+  return false
+}
+
 export function convertBskyAppUrlIfNeeded(url: string): string {
   if (isBskyAppUrl(url)) {
     try {