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:
parent
fac1af43b0
commit
4291711f1d
4 changed files with 88 additions and 56 deletions
|
@ -78,7 +78,10 @@ export interface FeedPostSliceItem {
|
|||
uri: string
|
||||
post: AppBskyFeedDefs.PostView
|
||||
record: AppBskyFeedPost.Record
|
||||
reason?: AppBskyFeedDefs.ReasonRepost | ReasonFeedSource
|
||||
reason?:
|
||||
| AppBskyFeedDefs.ReasonRepost
|
||||
| ReasonFeedSource
|
||||
| {[k: string]: unknown; $type: string}
|
||||
feedContext: string | undefined
|
||||
moderation: ModerationDecision
|
||||
parentAuthor?: AppBskyActorDefs.ProfileViewBasic
|
||||
|
@ -323,7 +326,7 @@ export function usePostFeedQuery(
|
|||
)
|
||||
}
|
||||
|
||||
return {
|
||||
const feedPostSlice: FeedPostSlice = {
|
||||
_reactKey: slice._reactKey,
|
||||
_isFeedPostSlice: true,
|
||||
rootUri: slice.rootItem.post.uri,
|
||||
|
@ -341,15 +344,23 @@ export function usePostFeedQuery(
|
|||
AppBskyFeedPost.validateRecord(item.post.record)
|
||||
.success
|
||||
) {
|
||||
const parentAuthor =
|
||||
item.reply?.parent?.author ??
|
||||
slice.items[i + 1]?.reply?.grandparentAuthor
|
||||
const parent = item.reply?.parent
|
||||
let parentAuthor:
|
||||
| AppBskyActorDefs.ProfileViewBasic
|
||||
| undefined
|
||||
if (AppBskyFeedDefs.isPostView(parent)) {
|
||||
parentAuthor = parent.author
|
||||
}
|
||||
if (!parentAuthor) {
|
||||
parentAuthor =
|
||||
slice.items[i + 1]?.reply?.grandparentAuthor
|
||||
}
|
||||
const replyRef = item.reply
|
||||
const isParentBlocked = AppBskyFeedDefs.isBlockedPost(
|
||||
replyRef?.parent,
|
||||
)
|
||||
|
||||
return {
|
||||
const feedPostSliceItem: FeedPostSliceItem = {
|
||||
_reactKey: `${slice._reactKey}-${i}-${item.post.uri}`,
|
||||
uri: item.post.uri,
|
||||
post: item.post,
|
||||
|
@ -363,13 +374,15 @@ export function usePostFeedQuery(
|
|||
parentAuthor,
|
||||
isParentBlocked,
|
||||
}
|
||||
return feedPostSliceItem
|
||||
}
|
||||
return undefined
|
||||
})
|
||||
.filter(Boolean) as FeedPostSliceItem[],
|
||||
.filter(<T>(n?: T): n is T => Boolean(n)),
|
||||
}
|
||||
return feedPostSlice
|
||||
})
|
||||
.filter(Boolean) as FeedPostSlice[],
|
||||
.filter(<T>(n?: T): n is T => Boolean(n)),
|
||||
})),
|
||||
],
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue