diff --git a/src/lib/moderation.ts b/src/lib/moderation.ts index 6849674427..3c3690a15c 100644 --- a/src/lib/moderation.ts +++ b/src/lib/moderation.ts @@ -61,7 +61,7 @@ export function isCauseALabelOnUri( export function getModerationCauseKey(cause: ModerationCause): string { const source = cause.source.type === 'labeler' - ? cause.source.labeler.did + ? cause.source.did : cause.source.type === 'list' ? cause.source.list.uri : 'user' diff --git a/src/screens/Onboarding/StepModeration/AdultContentEnabledPref.tsx b/src/screens/Onboarding/StepModeration/AdultContentEnabledPref.tsx index b38b3df1ed..3a9a22bb52 100644 --- a/src/screens/Onboarding/StepModeration/AdultContentEnabledPref.tsx +++ b/src/screens/Onboarding/StepModeration/AdultContentEnabledPref.tsx @@ -56,7 +56,9 @@ export function AdultContentEnabledPref({ try { mutate({ - enabled: !(variables?.enabled ?? preferences?.adultContentEnabled), + enabled: !( + variables?.enabled ?? preferences?.moderationOpts.adultContentEnabled + ), }) } catch (e) { Toast.show( @@ -75,7 +77,10 @@ export function AdultContentEnabledPref({ { diff --git a/src/state/queries/actor-autocomplete.ts b/src/state/queries/actor-autocomplete.ts index 3159ad7aaf..329118a237 100644 --- a/src/state/queries/actor-autocomplete.ts +++ b/src/state/queries/actor-autocomplete.ts @@ -6,17 +6,10 @@ import {logger} from '#/logger' import {getAgent} from '#/state/session' import {useMyFollowsQuery} from '#/state/queries/my-follows' import {STALE} from '#/state/queries' -import { - DEFAULT_LOGGED_OUT_PREFERENCES, - getModerationOpts, - useModerationOpts, -} from './preferences' +import {DEFAULT_LOGGED_OUT_PREFERENCES, useModerationOpts} from './preferences' import {isInvalidHandle} from '#/lib/strings/handles' -const DEFAULT_MOD_OPTS = getModerationOpts({ - userDid: '', - preferences: DEFAULT_LOGGED_OUT_PREFERENCES, -}) +const DEFAULT_MOD_OPTS = DEFAULT_LOGGED_OUT_PREFERENCES.moderationOpts export const RQKEY = (prefix: string) => ['actor-autocomplete', prefix] diff --git a/src/state/queries/post-feed.ts b/src/state/queries/post-feed.ts index 3200090897..7eebce6eab 100644 --- a/src/state/queries/post-feed.ts +++ b/src/state/queries/post-feed.ts @@ -24,7 +24,6 @@ import {STALE} from '#/state/queries' import {precacheFeedPostProfiles} from './profile' import {getAgent} from '#/state/session' import {DEFAULT_LOGGED_OUT_PREFERENCES} from '#/state/queries/preferences/const' -import {getModerationOpts} from '#/state/queries/preferences/moderation' import {KnownError} from '#/view/com/posts/FeedErrorMessage' import {embedViewRecordToPostView, getEmbeddedPost} from './util' import {useModerationOpts} from './preferences' @@ -429,11 +428,10 @@ function assertSomePostsPassModeration(feed: AppBskyFeedDefs.FeedViewPost[]) { let somePostsPassModeration = false for (const item of feed) { - const moderationOpts = getModerationOpts({ - userDid: '', - preferences: DEFAULT_LOGGED_OUT_PREFERENCES, - }) - const moderation = moderatePost(item.post, moderationOpts) + const moderation = moderatePost( + item.post, + DEFAULT_LOGGED_OUT_PREFERENCES.moderationOpts, + ) if (!moderation.content.filter) { // we have a sfw post diff --git a/src/state/queries/preferences/const.ts b/src/state/queries/preferences/const.ts index 2d9d02994e..84db427a95 100644 --- a/src/state/queries/preferences/const.ts +++ b/src/state/queries/preferences/const.ts @@ -29,21 +29,16 @@ export const DEFAULT_PROD_FEEDS = { export const DEFAULT_LOGGED_OUT_PREFERENCES: UsePreferencesQueryResponse = { birthDate: new Date('2022-11-17'), // TODO(pwi) - adultContentEnabled: false, feeds: { saved: [], pinned: [], unpinned: [], }, - // labels are undefined until set by user - contentLabels: { - nsfw: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.nsfw, - nudity: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.nudity, - suggestive: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.suggestive, - gore: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.gore, - hate: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.hate, - spam: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.spam, - impersonation: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES.impersonation, + moderationOpts: { + userDid: '', + adultContentEnabled: false, + labelGroups: DEFAULT_LOGGED_OUT_LABEL_PREFERENCES, + mods: [], }, feedViewPrefs: DEFAULT_HOME_FEED_PREFS, threadViewPrefs: DEFAULT_THREAD_VIEW_PREFS, diff --git a/src/state/queries/preferences/index.ts b/src/state/queries/preferences/index.ts index 632d31a13c..a3dedb5231 100644 --- a/src/state/queries/preferences/index.ts +++ b/src/state/queries/preferences/index.ts @@ -4,20 +4,17 @@ import {LabelPreference, BskyFeedViewPreference} from '@atproto/api' import {track} from '#/lib/analytics/analytics' import {getAge} from '#/lib/strings/time' -import {useSession, getAgent} from '#/state/session' -import {DEFAULT_LABEL_PREFERENCES} from '#/state/queries/preferences/moderation' +import {getAgent} from '#/state/session' import { ConfigurableLabelGroup, UsePreferencesQueryResponse, ThreadViewPreferences, } from '#/state/queries/preferences/types' -import {temp__migrateLabelPref} from '#/state/queries/preferences/util' import { DEFAULT_HOME_FEED_PREFS, DEFAULT_THREAD_VIEW_PREFS, DEFAULT_LOGGED_OUT_PREFERENCES, } from '#/state/queries/preferences/const' -import {getModerationOpts} from '#/state/queries/preferences/moderation' import {STALE} from '#/state/queries' import {useHiddenPosts} from '#/state/preferences/hidden-posts' @@ -50,32 +47,6 @@ export function usePreferencesQuery() { return !res.feeds.pinned?.includes(f) }) || [], }, - // labels are undefined until set by user - contentLabels: { - nsfw: temp__migrateLabelPref( - res.contentLabels?.nsfw || DEFAULT_LABEL_PREFERENCES.nsfw, - ), - nudity: temp__migrateLabelPref( - res.contentLabels?.nudity || DEFAULT_LABEL_PREFERENCES.nudity, - ), - suggestive: temp__migrateLabelPref( - res.contentLabels?.suggestive || - DEFAULT_LABEL_PREFERENCES.suggestive, - ), - gore: temp__migrateLabelPref( - res.contentLabels?.gore || DEFAULT_LABEL_PREFERENCES.gore, - ), - hate: temp__migrateLabelPref( - res.contentLabels?.hate || DEFAULT_LABEL_PREFERENCES.hate, - ), - spam: temp__migrateLabelPref( - res.contentLabels?.spam || DEFAULT_LABEL_PREFERENCES.spam, - ), - impersonation: temp__migrateLabelPref( - res.contentLabels?.impersonation || - DEFAULT_LABEL_PREFERENCES.impersonation, - ), - }, feedViewPrefs: { ...DEFAULT_HOME_FEED_PREFS, ...(res.feedViewPrefs.home || {}), @@ -93,23 +64,18 @@ export function usePreferencesQuery() { } export function useModerationOpts() { - const {currentAccount} = useSession() const prefs = usePreferencesQuery() const hiddenPosts = useHiddenPosts() const opts = useMemo(() => { if (!prefs.data) { return } - const moderationOpts = getModerationOpts({ - userDid: currentAccount?.did || '', - preferences: prefs.data, - }) - + const moderationOpts = prefs.data.moderationOpts return { ...moderationOpts, hiddenPosts, } - }, [currentAccount?.did, prefs.data, hiddenPosts]) + }, [prefs.data, hiddenPosts]) return opts } diff --git a/src/state/queries/preferences/moderation.ts b/src/state/queries/preferences/moderation.ts index 58a5112c91..f5d3367018 100644 --- a/src/state/queries/preferences/moderation.ts +++ b/src/state/queries/preferences/moderation.ts @@ -1,13 +1,8 @@ -import { - LabelPreference, - ComAtprotoLabelDefs, - ModerationOpts, -} from '@atproto/api' +import {ComAtprotoLabelDefs, DEFAULT_LABEL_GROUP_SETTINGS} from '@atproto/api' import { LabelGroup, ConfigurableLabelGroup, - UsePreferencesQueryResponse, } from '#/state/queries/preferences/types' export type Label = ComAtprotoLabelDefs.Label @@ -21,36 +16,18 @@ export type LabelGroupConfig = { values: string[] } -export const DEFAULT_LABEL_PREFERENCES: Record< - ConfigurableLabelGroup, - LabelPreference -> = { - nsfw: 'hide', - nudity: 'warn', - suggestive: 'warn', - gore: 'warn', - hate: 'hide', - spam: 'hide', - impersonation: 'hide', -} - /** * More strict than our default settings for logged in users. * * TODO(pwi) */ -export const DEFAULT_LOGGED_OUT_LABEL_PREFERENCES: Record< - ConfigurableLabelGroup, - LabelPreference -> = { - nsfw: 'hide', - nudity: 'hide', - suggestive: 'hide', - gore: 'hide', - hate: 'hide', - spam: 'hide', - impersonation: 'hide', -} +export const DEFAULT_LOGGED_OUT_LABEL_PREFERENCES: typeof DEFAULT_LABEL_GROUP_SETTINGS = + Object.fromEntries( + Object.entries(DEFAULT_LABEL_GROUP_SETTINGS).map(([key, _pref]) => [ + key, + 'hide', + ]), + ) export const CONFIGURABLE_LABEL_GROUPS: Record< ConfigurableLabelGroup, @@ -110,44 +87,3 @@ export const CONFIGURABLE_LABEL_GROUPS: Record< values: ['impersonation'], }, } - -export function getModerationOpts({ - userDid, - preferences, -}: { - userDid: string - preferences: UsePreferencesQueryResponse -}): ModerationOpts { - return { - userDid: userDid, - adultContentEnabled: preferences.adultContentEnabled, - labels: { - porn: preferences.contentLabels.nsfw, - sexual: preferences.contentLabels.suggestive, - nudity: preferences.contentLabels.nudity, - nsfl: preferences.contentLabels.gore, - corpse: preferences.contentLabels.gore, - gore: preferences.contentLabels.gore, - torture: preferences.contentLabels.gore, - 'self-harm': preferences.contentLabels.gore, - 'intolerant-race': preferences.contentLabels.hate, - 'intolerant-gender': preferences.contentLabels.hate, - 'intolerant-sexual-orientation': preferences.contentLabels.hate, - 'intolerant-religion': preferences.contentLabels.hate, - intolerant: preferences.contentLabels.hate, - 'icon-intolerant': preferences.contentLabels.hate, - spam: preferences.contentLabels.spam, - impersonation: preferences.contentLabels.impersonation, - scam: 'warn', - }, - labelers: [ - { - labeler: { - did: '', - displayName: 'Bluesky Social', - }, - labels: {}, - }, - ], - } -} diff --git a/src/state/queries/preferences/types.ts b/src/state/queries/preferences/types.ts index 45c9eed7de..5aa9676a5d 100644 --- a/src/state/queries/preferences/types.ts +++ b/src/state/queries/preferences/types.ts @@ -1,6 +1,5 @@ import { BskyPreferences, - LabelPreference, BskyThreadViewPreference, BskyFeedViewPreference, } from '@atproto/api' @@ -35,12 +34,6 @@ export type UsePreferencesQueryResponse = Omit< BskyPreferences, 'contentLabels' | 'feedViewPrefs' | 'feeds' > & { - /* - * Content labels previously included 'show', which has been deprecated in - * favor of 'ignore'. The API can return legacy data from the database, and - * we clean up the data in `usePreferencesQuery`. - */ - contentLabels: Record feedViewPrefs: BskyFeedViewPreference & { lab_mergeFeedEnabled?: boolean } diff --git a/src/state/queries/preferences/util.ts b/src/state/queries/preferences/util.ts deleted file mode 100644 index 7b8160c283..0000000000 --- a/src/state/queries/preferences/util.ts +++ /dev/null @@ -1,16 +0,0 @@ -import {LabelPreference} from '@atproto/api' - -/** - * Content labels previously included 'show', which has been deprecated in - * favor of 'ignore'. The API can return legacy data from the database, and - * we clean up the data in `usePreferencesQuery`. - * - * @deprecated - */ -export function temp__migrateLabelPref( - pref: LabelPreference | 'show', -): LabelPreference { - // @ts-ignore - if (pref === 'show') return 'ignore' - return pref -} diff --git a/src/view/com/modals/ContentFilteringSettings.tsx b/src/view/com/modals/ContentFilteringSettings.tsx index 328d23dc29..77f0082b31 100644 --- a/src/view/com/modals/ContentFilteringSettings.tsx +++ b/src/view/com/modals/ContentFilteringSettings.tsx @@ -49,22 +49,22 @@ export function Component({}: {}) { @@ -119,7 +119,9 @@ function AdultContentEnabledPref() { try { mutate({ - enabled: !(variables?.enabled ?? preferences?.adultContentEnabled), + enabled: !( + variables?.enabled ?? preferences?.moderationOpts.adultContentEnabled + ), }) } catch (e) { Toast.show( @@ -136,7 +138,7 @@ function AdultContentEnabledPref() { return ( {isIOS ? ( - preferences?.adultContentEnabled ? null : ( + preferences?.moderationOpts.adultContentEnabled ? null : ( Adult content can only be enabled via the Web at{' '} @@ -165,7 +167,10 @@ function AdultContentEnabledPref() { @@ -196,7 +201,7 @@ function ContentLabelPref({ disabled?: boolean }) { const pal = usePalette('default') - const visibility = preferences?.contentLabels?.[labelGroup] + const visibility = preferences?.moderationOpts.labelGroups?.[labelGroup] const {mutate, variables} = usePreferencesSetContentLabelMutation() const onChange = React.useCallback( diff --git a/src/view/com/moderation/AdultContentPref.tsx b/src/view/com/moderation/AdultContentPref.tsx index a9be38b748..6e34fcaa37 100644 --- a/src/view/com/moderation/AdultContentPref.tsx +++ b/src/view/com/moderation/AdultContentPref.tsx @@ -34,7 +34,9 @@ export function AdultContentEnabledPref() { try { mutate({ - enabled: !(variables?.enabled ?? preferences?.adultContentEnabled), + enabled: !( + variables?.enabled ?? preferences?.moderationOpts.adultContentEnabled + ), }) } catch (e) { Toast.show( @@ -47,7 +49,7 @@ export function AdultContentEnabledPref() { return ( {isIOS ? ( - preferences?.adultContentEnabled ? null : ( + preferences?.moderationOpts.adultContentEnabled ? null : ( @@ -68,7 +70,9 @@ export function AdultContentEnabledPref() { type="default-light" label={_(msg`Enable Adult Content`)} isSelected={ - variables?.enabled ?? preferences?.adultContentEnabled ?? false + variables?.enabled ?? + preferences?.moderationOpts.adultContentEnabled ?? + false } onPress={onToggleAdultContent} style={styles.toggleBtn} diff --git a/src/view/com/moderation/LabelGroupPref.tsx b/src/view/com/moderation/LabelGroupPref.tsx index 799428e924..187ded725f 100644 --- a/src/view/com/moderation/LabelGroupPref.tsx +++ b/src/view/com/moderation/LabelGroupPref.tsx @@ -23,7 +23,7 @@ export function LabelGroupPref({ disabled?: boolean }) { const pal = usePalette('default') - const visibility = preferences?.contentLabels?.[labelGroup] + const visibility = preferences?.moderationOpts.labelGroups?.[labelGroup] const {mutate, variables} = usePreferencesSetContentLabelMutation() const onChange = React.useCallback( diff --git a/src/view/com/moderation/ModServicePrefs.tsx b/src/view/com/moderation/ModServicePrefs.tsx index e7e45e5ce8..1234281769 100644 --- a/src/view/com/moderation/ModServicePrefs.tsx +++ b/src/view/com/moderation/ModServicePrefs.tsx @@ -17,22 +17,22 @@ export function ModServicePrefs({}: {}) { diff --git a/src/view/screens/DebugMod.tsx b/src/view/screens/DebugMod.tsx index 7e588d59b7..c4ecddf761 100644 --- a/src/view/screens/DebugMod.tsx +++ b/src/view/screens/DebugMod.tsx @@ -3,14 +3,12 @@ import {NativeStackScreenProps, CommonNavigatorParams} from 'lib/routes/types' import {View} from 'react-native' import { LABELS, - LABEL_GROUPS, mock, moderatePost, moderateProfile, PostModeration, ProfileModeration, ModerationUI, - LabelPreference, AppBskyActorDefs, AppBskyFeedDefs, } from '@atproto/api' @@ -39,12 +37,10 @@ const MOCK_MOD_OPTS = { userDid: 'at://did:web:alice', adultContentEnabled: true, labelGroups: {}, - labelers: [ + mods: [ { - labeler: {did: 'did:plc:fake-labeler'}, - labelGroups: Object.fromEntries( - Object.keys(LABEL_GROUPS).map(key => [key, 'hide' as LabelPreference]), - ), + did: 'did:plc:fake-labeler', + enabled: true, }, ], } @@ -201,7 +197,7 @@ export const DebugModScreen = ({}: NativeStackScreenProps<

Account{' '} -

in listing

+

in listing

Account{' '} -

+

viewing directly

- + + {' '}

Bob Robertson

-

+

@bob.bsky.social · 5m

@@ -302,7 +300,7 @@ function MockPost({ moderationDecisions={moderation.decisions}>

Bob Robertson

-

+

@bob.bsky.social · 5m

@@ -341,7 +339,7 @@ function MockAccountCard({ {sanitizeDisplayName('Bob Robertson', moderation.profile)}{' '}

-

@bob.bsky.social

+

@bob.bsky.social

Thought leader or something.

@@ -370,19 +368,20 @@ function MockAccountCard({ function MockAccountScreen({ label, profile, - moderation, }: { label: string profile: AppBskyActorDefs.ProfileViewBasic - moderation: ProfileModeration }) { const t = useTheme() return ( - + {/* @@ -400,12 +399,12 @@ function MockAccountScreen({ style={[ a.pb_2xl, a.px_xl, - t.atoms.border, + t.atoms.border_contrast_medium, a.border_b, {paddingTop: 60}, ]}>

Bob Robertson

-

@bob.bsky.social

+

@bob.bsky.social

Thought leader or something.

*/} @@ -435,7 +434,7 @@ function Flag({v, label}: {v: boolean | undefined; label: string}) { a.align_center, a.rounded_xs, a.border, - t.atoms.border, + t.atoms.border_contrast_medium, { backgroundColor: v ? t.palette.black : t.palette.white, width: 14,