about summary refs log tree commit diff
path: root/src/view
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2024-08-02 13:05:33 -0500
committerGitHub <noreply@github.com>2024-08-02 13:05:33 -0500
commitc3d8beee6dc141ced2c41795f90b3309a2bc75a2 (patch)
treee2aa55a6e79616ec989b7426e2c46b4cd56b91e2 /src/view
parent293ac6fab21f26baa8347c998f3a50224112c7c5 (diff)
downloadvoidsky-c3d8beee6dc141ced2c41795f90b3309a2bc75a2.tar.zst
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
Diffstat (limited to 'src/view')
-rw-r--r--src/view/com/feeds/ProfileFeedgens.tsx83
-rw-r--r--src/view/com/lists/ProfileLists.tsx9
-rw-r--r--src/view/com/util/post-embeds/index.tsx50
-rw-r--r--src/view/screens/ProfileList.tsx127
4 files changed, 164 insertions, 105 deletions
diff --git a/src/view/com/feeds/ProfileFeedgens.tsx b/src/view/com/feeds/ProfileFeedgens.tsx
index 831ab4d1d..6f98cc49a 100644
--- a/src/view/com/feeds/ProfileFeedgens.tsx
+++ b/src/view/com/feeds/ProfileFeedgens.tsx
@@ -129,46 +129,49 @@ export const ProfileFeedgens = React.forwardRef<
   // rendering
   // =
 
-  const renderItem = ({item, index}: ListRenderItemInfo<any>) => {
-    if (item === EMPTY) {
-      return (
-        <EmptyState
-          icon="hashtag"
-          message={_(msg`You have no feeds.`)}
-          testID="listsEmpty"
-        />
-      )
-    } else if (item === ERROR_ITEM) {
-      return (
-        <ErrorMessage message={cleanError(error)} onPressTryAgain={refetch} />
-      )
-    } else if (item === LOAD_MORE_ERROR_ITEM) {
-      return (
-        <LoadMoreRetryBtn
-          label={_(
-            msg`There was an issue fetching your lists. Tap here to try again.`,
-          )}
-          onPress={onPressRetryLoadMore}
-        />
-      )
-    } else if (item === LOADING) {
-      return <FeedLoadingPlaceholder />
-    }
-    if (preferences) {
-      return (
-        <View
-          style={[
-            (index !== 0 || isWeb) && a.border_t,
-            t.atoms.border_contrast_low,
-            a.px_lg,
-            a.py_lg,
-          ]}>
-          <FeedCard.Default view={item} />
-        </View>
-      )
-    }
-    return null
-  }
+  const renderItem = React.useCallback(
+    ({item, index}: ListRenderItemInfo<any>) => {
+      if (item === EMPTY) {
+        return (
+          <EmptyState
+            icon="hashtag"
+            message={_(msg`You have no feeds.`)}
+            testID="listsEmpty"
+          />
+        )
+      } else if (item === ERROR_ITEM) {
+        return (
+          <ErrorMessage message={cleanError(error)} onPressTryAgain={refetch} />
+        )
+      } else if (item === LOAD_MORE_ERROR_ITEM) {
+        return (
+          <LoadMoreRetryBtn
+            label={_(
+              msg`There was an issue fetching your lists. Tap here to try again.`,
+            )}
+            onPress={onPressRetryLoadMore}
+          />
+        )
+      } else if (item === LOADING) {
+        return <FeedLoadingPlaceholder />
+      }
+      if (preferences) {
+        return (
+          <View
+            style={[
+              (index !== 0 || isWeb) && a.border_t,
+              t.atoms.border_contrast_low,
+              a.px_lg,
+              a.py_lg,
+            ]}>
+            <FeedCard.Default view={item} />
+          </View>
+        )
+      }
+      return null
+    },
+    [_, t, error, refetch, onPressRetryLoadMore, preferences],
+  )
 
   React.useEffect(() => {
     if (enabled && scrollElRef.current) {
diff --git a/src/view/com/lists/ProfileLists.tsx b/src/view/com/lists/ProfileLists.tsx
index dc385d436..f633774c7 100644
--- a/src/view/com/lists/ProfileLists.tsx
+++ b/src/view/com/lists/ProfileLists.tsx
@@ -75,12 +75,7 @@ export const ProfileLists = React.forwardRef<SectionRef, ProfileListsProps>(
         items = items.concat([EMPTY])
       } else if (data?.pages) {
         for (const page of data?.pages) {
-          items = items.concat(
-            page.lists.map(l => ({
-              ...l,
-              _reactKey: l.uri,
-            })),
-          )
+          items = items.concat(page.lists)
         }
       }
       if (isError && !isEmpty) {
@@ -192,7 +187,7 @@ export const ProfileLists = React.forwardRef<SectionRef, ProfileListsProps>(
           testID={testID ? `${testID}-flatlist` : undefined}
           ref={scrollElRef}
           data={items}
-          keyExtractor={(item: any) => item._reactKey}
+          keyExtractor={(item: any) => item._reactKey || item.uri}
           renderItem={renderItemInner}
           refreshing={isPTRing}
           onRefresh={onRefresh}
diff --git a/src/view/com/util/post-embeds/index.tsx b/src/view/com/util/post-embeds/index.tsx
index a0dc94e4d..0462212fb 100644
--- a/src/view/com/util/post-embeds/index.tsx
+++ b/src/view/com/util/post-embeds/index.tsx
@@ -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,
diff --git a/src/view/screens/ProfileList.tsx b/src/view/screens/ProfileList.tsx
index 0ed44758d..bf13791ae 100644
--- a/src/view/screens/ProfileList.tsx
+++ b/src/view/screens/ProfileList.tsx
@@ -1,6 +1,12 @@
 import React, {useCallback, useMemo} from 'react'
 import {Pressable, StyleSheet, View} from 'react-native'
-import {AppBskyGraphDefs, AtUri, RichText as RichTextAPI} from '@atproto/api'
+import {
+  AppBskyGraphDefs,
+  AtUri,
+  moderateUserList,
+  ModerationOpts,
+  RichText as RichTextAPI,
+} from '@atproto/api'
 import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
 import {msg, Trans} from '@lingui/macro'
 import {useLingui} from '@lingui/react'
@@ -14,6 +20,7 @@ import {logger} from '#/logger'
 import {isNative, isWeb} from '#/platform/detection'
 import {listenSoftReset} from '#/state/events'
 import {useModalControls} from '#/state/modals'
+import {useModerationOpts} from '#/state/preferences/moderation-opts'
 import {
   useListBlockMutation,
   useListDeleteMutation,
@@ -62,6 +69,7 @@ import * as Toast from 'view/com/util/Toast'
 import {CenteredView} from 'view/com/util/Views'
 import {atoms as a, useTheme} from '#/alf'
 import {useDialogControl} from '#/components/Dialog'
+import {ScreenHider} from '#/components/moderation/ScreenHider'
 import * as Prompt from '#/components/Prompt'
 import {ReportDialog, useReportDialogControl} from '#/components/ReportDialog'
 import {RichText} from '#/components/RichText'
@@ -81,6 +89,7 @@ export function ProfileListScreen(props: Props) {
     AtUri.make(handleOrDid, 'app.bsky.graph.list', rkey).toString(),
   )
   const {data: list, error: listError} = useListQuery(resolvedUri?.uri)
+  const moderationOpts = useModerationOpts()
 
   if (resolveError) {
     return (
@@ -101,8 +110,13 @@ export function ProfileListScreen(props: Props) {
     )
   }
 
-  return resolvedUri && list ? (
-    <ProfileListScreenLoaded {...props} uri={resolvedUri.uri} list={list} />
+  return resolvedUri && list && moderationOpts ? (
+    <ProfileListScreenLoaded
+      {...props}
+      uri={resolvedUri.uri}
+      list={list}
+      moderationOpts={moderationOpts}
+    />
   ) : (
     <LoadingScreen />
   )
@@ -112,7 +126,12 @@ function ProfileListScreenLoaded({
   route,
   uri,
   list,
-}: Props & {uri: string; list: AppBskyGraphDefs.ListView}) {
+  moderationOpts,
+}: Props & {
+  uri: string
+  list: AppBskyGraphDefs.ListView
+  moderationOpts: ModerationOpts
+}) {
   const {_} = useLingui()
   const queryClient = useQueryClient()
   const {openComposer} = useComposerControls()
@@ -124,6 +143,10 @@ function ProfileListScreenLoaded({
   const isCurateList = list.purpose === 'app.bsky.graph.defs#curatelist'
   const isScreenFocused = useIsFocused()
 
+  const moderation = React.useMemo(() => {
+    return moderateUserList(list, moderationOpts)
+  }, [list, moderationOpts])
+
   useSetTitle(list.name)
 
   useFocusEffect(
@@ -161,26 +184,65 @@ function ProfileListScreenLoaded({
 
   if (isCurateList) {
     return (
+      <ScreenHider
+        screenDescription={'list'}
+        modui={moderation.ui('contentView')}>
+        <View style={s.hContentRegion}>
+          <PagerWithHeader
+            items={SECTION_TITLES_CURATE}
+            isHeaderReady={true}
+            renderHeader={renderHeader}
+            onCurrentPageSelected={onCurrentPageSelected}>
+            {({headerHeight, scrollElRef, isFocused}) => (
+              <FeedSection
+                ref={feedSectionRef}
+                feed={`list|${uri}`}
+                scrollElRef={scrollElRef as ListRef}
+                headerHeight={headerHeight}
+                isFocused={isScreenFocused && isFocused}
+              />
+            )}
+            {({headerHeight, scrollElRef}) => (
+              <AboutSection
+                ref={aboutSectionRef}
+                scrollElRef={scrollElRef as ListRef}
+                list={list}
+                onPressAddUser={onPressAddUser}
+                headerHeight={headerHeight}
+              />
+            )}
+          </PagerWithHeader>
+          <FAB
+            testID="composeFAB"
+            onPress={() => openComposer({})}
+            icon={
+              <ComposeIcon2
+                strokeWidth={1.5}
+                size={29}
+                style={{color: 'white'}}
+              />
+            }
+            accessibilityRole="button"
+            accessibilityLabel={_(msg`New post`)}
+            accessibilityHint=""
+          />
+        </View>
+      </ScreenHider>
+    )
+  }
+  return (
+    <ScreenHider
+      screenDescription={_(msg`list`)}
+      modui={moderation.ui('contentView')}>
       <View style={s.hContentRegion}>
         <PagerWithHeader
-          items={SECTION_TITLES_CURATE}
+          items={SECTION_TITLES_MOD}
           isHeaderReady={true}
-          renderHeader={renderHeader}
-          onCurrentPageSelected={onCurrentPageSelected}>
-          {({headerHeight, scrollElRef, isFocused}) => (
-            <FeedSection
-              ref={feedSectionRef}
-              feed={`list|${uri}`}
-              scrollElRef={scrollElRef as ListRef}
-              headerHeight={headerHeight}
-              isFocused={isScreenFocused && isFocused}
-            />
-          )}
+          renderHeader={renderHeader}>
           {({headerHeight, scrollElRef}) => (
             <AboutSection
-              ref={aboutSectionRef}
-              scrollElRef={scrollElRef as ListRef}
               list={list}
+              scrollElRef={scrollElRef as ListRef}
               onPressAddUser={onPressAddUser}
               headerHeight={headerHeight}
             />
@@ -201,34 +263,7 @@ function ProfileListScreenLoaded({
           accessibilityHint=""
         />
       </View>
-    )
-  }
-  return (
-    <View style={s.hContentRegion}>
-      <PagerWithHeader
-        items={SECTION_TITLES_MOD}
-        isHeaderReady={true}
-        renderHeader={renderHeader}>
-        {({headerHeight, scrollElRef}) => (
-          <AboutSection
-            list={list}
-            scrollElRef={scrollElRef as ListRef}
-            onPressAddUser={onPressAddUser}
-            headerHeight={headerHeight}
-          />
-        )}
-      </PagerWithHeader>
-      <FAB
-        testID="composeFAB"
-        onPress={() => openComposer({})}
-        icon={
-          <ComposeIcon2 strokeWidth={1.5} size={29} style={{color: 'white'}} />
-        }
-        accessibilityRole="button"
-        accessibilityLabel={_(msg`New post`)}
-        accessibilityHint=""
-      />
-    </View>
+    </ScreenHider>
   )
 }