Hoist moderation, attempt to fill feed up to 30 (#2134)
* Move moderatePost up to feed query * Attemt to fill page up to 30 * Add the 'ensure full page' behavior to notifs --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
This commit is contained in:
parent
940fc0ea5c
commit
174a1622c9
4 changed files with 112 additions and 83 deletions
|
@ -27,7 +27,6 @@ import {
|
|||
usePostFeedQuery,
|
||||
pollLatest,
|
||||
} from '#/state/queries/post-feed'
|
||||
import {useModerationOpts} from '#/state/queries/preferences'
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {listenPostCreated} from '#/state/events'
|
||||
import {useSession} from '#/state/session'
|
||||
|
@ -82,8 +81,10 @@ let Feed = ({
|
|||
const [isPTRing, setIsPTRing] = React.useState(false)
|
||||
const checkForNewRef = React.useRef<(() => void) | null>(null)
|
||||
|
||||
const moderationOpts = useModerationOpts()
|
||||
const opts = React.useMemo(() => ({enabled}), [enabled])
|
||||
const opts = React.useMemo(
|
||||
() => ({enabled, ignoreFilterFor}),
|
||||
[enabled, ignoreFilterFor],
|
||||
)
|
||||
const {
|
||||
data,
|
||||
isFetching,
|
||||
|
@ -144,7 +145,7 @@ let Feed = ({
|
|||
|
||||
const feedItems = React.useMemo(() => {
|
||||
let arr: any[] = []
|
||||
if (isFetched && moderationOpts) {
|
||||
if (isFetched) {
|
||||
if (isError && isEmpty) {
|
||||
arr = arr.concat([ERROR_ITEM])
|
||||
}
|
||||
|
@ -162,7 +163,7 @@ let Feed = ({
|
|||
arr.push(LOADING_ITEM)
|
||||
}
|
||||
return arr
|
||||
}, [isFetched, isError, isEmpty, data, moderationOpts])
|
||||
}, [isFetched, isError, isEmpty, data])
|
||||
|
||||
// events
|
||||
// =
|
||||
|
@ -224,24 +225,9 @@ let Feed = ({
|
|||
} else if (item === LOADING_ITEM) {
|
||||
return <PostFeedLoadingPlaceholder />
|
||||
}
|
||||
return (
|
||||
<FeedSlice
|
||||
slice={item}
|
||||
// we check for this before creating the feedItems array
|
||||
moderationOpts={moderationOpts!}
|
||||
ignoreFilterFor={ignoreFilterFor}
|
||||
/>
|
||||
)
|
||||
return <FeedSlice slice={item} />
|
||||
},
|
||||
[
|
||||
feed,
|
||||
error,
|
||||
onPressTryAgain,
|
||||
onPressRetryLoadMore,
|
||||
renderEmptyState,
|
||||
moderationOpts,
|
||||
ignoreFilterFor,
|
||||
],
|
||||
[feed, error, onPressTryAgain, onPressRetryLoadMore, renderEmptyState],
|
||||
)
|
||||
|
||||
const shouldRenderEndOfFeed =
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import React, {memo} from 'react'
|
||||
import {StyleSheet, View} from 'react-native'
|
||||
import {FeedPostSlice} from '#/state/queries/post-feed'
|
||||
import {AtUri, moderatePost, ModerationOpts} from '@atproto/api'
|
||||
import {AtUri} from '@atproto/api'
|
||||
import {Link} from '../util/Link'
|
||||
import {Text} from '../util/text/Text'
|
||||
import Svg, {Circle, Line} from 'react-native-svg'
|
||||
|
@ -9,29 +9,7 @@ import {FeedItem} from './FeedItem'
|
|||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {makeProfileLink} from 'lib/routes/links'
|
||||
|
||||
let FeedSlice = ({
|
||||
slice,
|
||||
ignoreFilterFor,
|
||||
moderationOpts,
|
||||
}: {
|
||||
slice: FeedPostSlice
|
||||
ignoreFilterFor?: string
|
||||
moderationOpts: ModerationOpts
|
||||
}): React.ReactNode => {
|
||||
const moderations = React.useMemo(() => {
|
||||
return slice.items.map(item => moderatePost(item.post, moderationOpts))
|
||||
}, [slice, moderationOpts])
|
||||
|
||||
// apply moderation filter
|
||||
for (let i = 0; i < slice.items.length; i++) {
|
||||
if (
|
||||
moderations[i]?.content.filter &&
|
||||
slice.items[i].post.author.did !== ignoreFilterFor
|
||||
) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
let FeedSlice = ({slice}: {slice: FeedPostSlice}): React.ReactNode => {
|
||||
if (slice.isThread && slice.items.length > 3) {
|
||||
const last = slice.items.length - 1
|
||||
return (
|
||||
|
@ -41,7 +19,7 @@ let FeedSlice = ({
|
|||
post={slice.items[0].post}
|
||||
record={slice.items[0].record}
|
||||
reason={slice.items[0].reason}
|
||||
moderation={moderations[0]}
|
||||
moderation={slice.items[0].moderation}
|
||||
isThreadParent={isThreadParentAt(slice.items, 0)}
|
||||
isThreadChild={isThreadChildAt(slice.items, 0)}
|
||||
/>
|
||||
|
@ -50,7 +28,7 @@ let FeedSlice = ({
|
|||
post={slice.items[1].post}
|
||||
record={slice.items[1].record}
|
||||
reason={slice.items[1].reason}
|
||||
moderation={moderations[1]}
|
||||
moderation={slice.items[1].moderation}
|
||||
isThreadParent={isThreadParentAt(slice.items, 1)}
|
||||
isThreadChild={isThreadChildAt(slice.items, 1)}
|
||||
/>
|
||||
|
@ -60,7 +38,7 @@ let FeedSlice = ({
|
|||
post={slice.items[last].post}
|
||||
record={slice.items[last].record}
|
||||
reason={slice.items[last].reason}
|
||||
moderation={moderations[last]}
|
||||
moderation={slice.items[last].moderation}
|
||||
isThreadParent={isThreadParentAt(slice.items, last)}
|
||||
isThreadChild={isThreadChildAt(slice.items, last)}
|
||||
isThreadLastChild
|
||||
|
@ -77,7 +55,7 @@ let FeedSlice = ({
|
|||
post={slice.items[i].post}
|
||||
record={slice.items[i].record}
|
||||
reason={slice.items[i].reason}
|
||||
moderation={moderations[i]}
|
||||
moderation={slice.items[i].moderation}
|
||||
isThreadParent={isThreadParentAt(slice.items, i)}
|
||||
isThreadChild={isThreadChildAt(slice.items, i)}
|
||||
isThreadLastChild={
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue