Respect labels on feeds and lists (#4818)

* Prep

* Pass in optional moderation to FeedCard

* Compute moderation decision, filter contentList contexts, pass into card

* Let's go a different route

* Filter from within search queries

* Use same search query for starter packs

* Filter lists from profile tabs

* Cleanup

* Filter from profile feeds

* Moderate post embeds

* Memoize

* Use ScreenHider on lists

* Hide both list types

* Fix crash on iOS in screen hider, fix lineheight

* Memoize renderItem

* Reuse objects to prevent re-renders
This commit is contained in:
Eric Bailey 2024-08-02 13:05:33 -05:00 committed by GitHub
parent 293ac6fab2
commit c3d8beee6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 261 additions and 145 deletions

View file

@ -15,11 +15,14 @@ import {
AppBskyEmbedRecordWithMedia,
AppBskyFeedDefs,
AppBskyGraphDefs,
moderateFeedGenerator,
moderateUserList,
ModerationDecision,
} from '@atproto/api'
import {ImagesLightbox, useLightboxControls} from '#/state/lightbox'
import {useLargeAltBadgeEnabled} from '#/state/preferences/large-alt-badge'
import {useModerationOpts} from '#/state/preferences/moderation-opts'
import {usePalette} from 'lib/hooks/usePalette'
import {FeedSourceCard} from 'view/com/feeds/FeedSourceCard'
import {atoms as a} from '#/alf'
@ -51,7 +54,6 @@ export function PostEmbeds({
style?: StyleProp<ViewStyle>
allowNestedQuotes?: boolean
}) {
const pal = usePalette('default')
const {openLightbox} = useLightboxControls()
const largeAltBadge = useLargeAltBadgeEnabled()
@ -72,22 +74,13 @@ export function PostEmbeds({
if (AppBskyEmbedRecord.isView(embed)) {
// custom feed embed (i.e. generator view)
// =
if (AppBskyFeedDefs.isGeneratorView(embed.record)) {
// TODO moderation
return (
<FeedSourceCard
feedUri={embed.record.uri}
style={[pal.view, pal.border, styles.customFeedOuter]}
showLikes
/>
)
return <MaybeFeedCard view={embed.record} />
}
// list embed
if (AppBskyGraphDefs.isListView(embed.record)) {
// TODO moderation
return <ListEmbed item={embed.record} />
return <MaybeListCard view={embed.record} />
}
if (AppBskyGraphDefs.isStarterPackViewBasic(embed.record)) {
@ -185,6 +178,39 @@ export function PostEmbeds({
return <View />
}
function MaybeFeedCard({view}: {view: AppBskyFeedDefs.GeneratorView}) {
const pal = usePalette('default')
const moderationOpts = useModerationOpts()
const moderation = React.useMemo(() => {
return moderationOpts
? moderateFeedGenerator(view, moderationOpts)
: undefined
}, [view, moderationOpts])
return (
<ContentHider modui={moderation?.ui('contentList')}>
<FeedSourceCard
feedUri={view.uri}
style={[pal.view, pal.border, styles.customFeedOuter]}
showLikes
/>
</ContentHider>
)
}
function MaybeListCard({view}: {view: AppBskyGraphDefs.ListView}) {
const moderationOpts = useModerationOpts()
const moderation = React.useMemo(() => {
return moderationOpts ? moderateUserList(view, moderationOpts) : undefined
}, [view, moderationOpts])
return (
<ContentHider modui={moderation?.ui('contentList')}>
<ListEmbed item={view} />
</ContentHider>
)
}
const styles = StyleSheet.create({
container: {
marginTop: 8,