about summary refs log tree commit diff
path: root/src/lib/api/index.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-04-07 11:51:20 -0500
committerGitHub <noreply@github.com>2023-04-07 11:51:20 -0500
commit0c9935f125f9132aca350ba3540d03bf8dfdbc8d (patch)
tree49008dacfa1ac6d7445a42446b00e46f4d5323ad /src/lib/api/index.ts
parent0407e93ef869e6461388ae9e8a3463b9de1247f3 (diff)
downloadvoidsky-0c9935f125f9132aca350ba3540d03bf8dfdbc8d.tar.zst
Filter out bad mentions instead of erroring during post (close #391) (#422)
Diffstat (limited to 'src/lib/api/index.ts')
-rw-r--r--src/lib/api/index.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts
index c40c2c1d5..457921d69 100644
--- a/src/lib/api/index.ts
+++ b/src/lib/api/index.ts
@@ -3,6 +3,7 @@ import {
   AppBskyEmbedExternal,
   AppBskyEmbedRecord,
   AppBskyEmbedRecordWithMedia,
+  AppBskyRichtextFacet,
   ComAtprotoRepoUploadBlob,
   RichText,
 } from '@atproto/api'
@@ -83,6 +84,17 @@ export async function post(store: RootStoreModel, opts: PostOpts) {
   opts.onStateChange?.('Processing...')
   await rt.detectFacets(store.agent)
 
+  // filter out any mention facets that didn't map to a user
+  rt.facets = rt.facets?.filter(facet => {
+    const mention = facet.features.find(feature =>
+      AppBskyRichtextFacet.isMention(feature),
+    )
+    if (mention && !mention.did) {
+      return false
+    }
+    return true
+  })
+
   if (opts.quote) {
     embed = {
       $type: 'app.bsky.embed.record',