about summary refs log tree commit diff
path: root/src/state/queries/threadgate.ts
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-07-25 19:53:12 +0100
committerGitHub <noreply@github.com>2024-07-25 19:53:12 +0100
commit4291711f1d4bf3921b1e805d7726b0764757f257 (patch)
tree37e9a0c20dbe2b723fe2bcf722b3550a94b5b8d8 /src/state/queries/threadgate.ts
parentfac1af43b0300e9d9be16641afc4fbeef0a91ccf (diff)
downloadvoidsky-4291711f1d4bf3921b1e805d7726b0764757f257.tar.zst
Fix sloppy filter(Boolean) types (#4830)
* Fix sloppy filter(Boolean) in threadgate

* Fix sloppy filter(Boolean) in Explore

* Fix sloppy filter(Boolean) in post-feed

* Harden FeedPostSliceItem.reason type def

* Harden parentAuthor types

* Fix lying component types, handle blocks
Diffstat (limited to 'src/state/queries/threadgate.ts')
-rw-r--r--src/state/queries/threadgate.ts22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/state/queries/threadgate.ts b/src/state/queries/threadgate.ts
index 67c6f8c08..c05d1f564 100644
--- a/src/state/queries/threadgate.ts
+++ b/src/state/queries/threadgate.ts
@@ -4,7 +4,7 @@ export type ThreadgateSetting =
   | {type: 'nobody'}
   | {type: 'mention'}
   | {type: 'following'}
-  | {type: 'list'; list: string}
+  | {type: 'list'; list: unknown}
 
 export function threadgateViewToSettings(
   threadgate: AppBskyFeedDefs.ThreadgateView | undefined,
@@ -21,18 +21,18 @@ export function threadgateViewToSettings(
   if (!record.allow?.length) {
     return [{type: 'nobody'}]
   }
-  return record.allow
+  const settings: ThreadgateSetting[] = record.allow
     .map(allow => {
+      let setting: ThreadgateSetting | undefined
       if (allow.$type === 'app.bsky.feed.threadgate#mentionRule') {
-        return {type: 'mention'}
+        setting = {type: 'mention'}
+      } else if (allow.$type === 'app.bsky.feed.threadgate#followingRule') {
+        setting = {type: 'following'}
+      } else if (allow.$type === 'app.bsky.feed.threadgate#listRule') {
+        setting = {type: 'list', list: allow.list}
       }
-      if (allow.$type === 'app.bsky.feed.threadgate#followingRule') {
-        return {type: 'following'}
-      }
-      if (allow.$type === 'app.bsky.feed.threadgate#listRule') {
-        return {type: 'list', list: allow.list}
-      }
-      return undefined
+      return setting
     })
-    .filter(Boolean) as ThreadgateSetting[]
+    .filter(<T>(n?: T): n is T => Boolean(n))
+  return settings
 }