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
This commit is contained in:
dan 2024-07-25 19:53:12 +01:00 committed by GitHub
parent fac1af43b0
commit 4291711f1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 88 additions and 56 deletions

View file

@ -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
}