From b73f9710f9fb8de4d9fc03c9fcf12f1493035b2c Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 15 Feb 2024 10:37:34 -0600 Subject: [PATCH] Handle reports on profile vs content --- src/components/dialogs/ReportDialog/index.tsx | 69 ++++++++++--------- src/lib/moderation.ts | 27 ++++++++ src/view/com/profile/ProfileHeader.tsx | 18 +++-- src/view/com/util/forms/PostDropdownBtn.tsx | 6 +- 4 files changed, 82 insertions(+), 38 deletions(-) diff --git a/src/components/dialogs/ReportDialog/index.tsx b/src/components/dialogs/ReportDialog/index.tsx index 69385b303b..f89a1e1624 100644 --- a/src/components/dialogs/ReportDialog/index.tsx +++ b/src/components/dialogs/ReportDialog/index.tsx @@ -33,7 +33,8 @@ import {useModServicesDetailedInfoQuery} from '#/state/queries/modservice' import { getLabelGroupsFromLabels, getModerationServiceTitle, - useConfigurableLabelGroups, + useConfigurableContentLabelGroups, + useConfigurableProfileLabelGroups, } from '#/lib/moderation' import {DMCA_LINK} from '#/components/dialogs/ReportDialog/const' import {Link} from '#/components/Link' @@ -42,12 +43,12 @@ import {SquareArrowTopRight_Stroke2_Corner0_Rounded as SquareArrowTopRight} from export type ReportDialogLabelIds = LabelGroupDefinition['id'] | 'other' export type ReportDialogProps = | { - type: 'post' + type: 'content' uri: string cid: string } | { - type: 'user' + type: 'profile' did: string } @@ -384,13 +385,15 @@ export function ReportDialog({ ReportDialogLabelIds | undefined >() const labelGroupStrings = useLabelGroupStrings() - const groups = useConfigurableLabelGroups() + const contentGroups = useConfigurableContentLabelGroups() + const profileGroups = useConfigurableProfileLabelGroups() + const groups = params.type === 'content' ? contentGroups : profileGroups const i18n = React.useMemo(() => { let title = _(msg`Report this post`) let description = _(msg`Why should this post be reviewed?`) - if (params.type === 'user') { + if (params.type === 'profile') { title = _(msg`Report this user`) description = _(msg`Why should this user be reviewed?`) } @@ -474,34 +477,36 @@ export function ReportDialog({ /> - - - - Need to report a copyright violation? - - - View details - - + {params.type === 'content' && ( + + + + Need to report a copyright violation? + + + View details + + + - + )} )} diff --git a/src/lib/moderation.ts b/src/lib/moderation.ts index 62fb16d52b..87875a862c 100644 --- a/src/lib/moderation.ts +++ b/src/lib/moderation.ts @@ -39,6 +39,33 @@ export function useConfigurableLabelGroups() { return React.useMemo(() => getConfigurableLabelGroups(), []) } +export function useConfigurableContentLabelGroups() { + return React.useMemo(() => { + const groups = getConfigurableLabelGroups() + return groups.filter(group => { + return group.labels.every(l => l.targets.includes('content')) + }) + }, []) +} + +export function useConfigurableProfileLabelGroups() { + return React.useMemo(() => { + const groups = getConfigurableLabelGroups() + return groups.filter(group => { + return group.labels.every(l => l.targets.includes('profile')) + }) + }, []) +} + +export function useConfigurableAccountLabelGroups() { + return React.useMemo(() => { + const groups = getConfigurableLabelGroups() + return groups.filter(group => { + return group.labels.every(l => l.targets.includes('account')) + }) + }, []) +} + export function getModerationServiceTitle({ displayName, handle, diff --git a/src/view/com/profile/ProfileHeader.tsx b/src/view/com/profile/ProfileHeader.tsx index 4579df7e31..de1b3decea 100644 --- a/src/view/com/profile/ProfileHeader.tsx +++ b/src/view/com/profile/ProfileHeader.tsx @@ -58,6 +58,9 @@ import {LabelInfo} from '../util/moderation/LabelInfo' import {useProfileShadow} from 'state/cache/profile-shadow' import * as ModerationServiceCard from '#/components/ModerationServiceCard' import {getModerationServiceTitle} from '#/lib/moderation' +import {useOpenGlobalDialog} from '#/components/dialogs' +import {ReportDialog} from '#/components/dialogs/ReportDialog' +import {NEW_REPORT_DIALOG_ENABLED} from '#/lib/build-flags' import {useTheme} from '#/alf' @@ -119,6 +122,7 @@ let ProfileHeader = ({ () => moderateProfile(profile, moderationOpts), [profile, moderationOpts], ) + const openDialog = useOpenGlobalDialog() const invalidateProfileQuery = React.useCallback(() => { queryClient.invalidateQueries({ @@ -280,11 +284,15 @@ let ProfileHeader = ({ const onPressReportAccount = React.useCallback(() => { track('ProfileHeader:ReportAccountButtonClicked') - openModal({ - name: 'report', - did: profile.did, - }) - }, [track, openModal, profile]) + if (NEW_REPORT_DIALOG_ENABLED) { + openDialog(ReportDialog, {type: 'profile', did: profile.did}) + } else { + openModal({ + name: 'report', + did: profile.did, + }) + } + }, [track, openModal, profile, openDialog]) const isMe = React.useMemo( () => currentAccount?.did === profile.did, diff --git a/src/view/com/util/forms/PostDropdownBtn.tsx b/src/view/com/util/forms/PostDropdownBtn.tsx index edb21f2380..616108ecef 100644 --- a/src/view/com/util/forms/PostDropdownBtn.tsx +++ b/src/view/com/util/forms/PostDropdownBtn.tsx @@ -214,7 +214,11 @@ let PostDropdownBtn = ({ label: _(msg`Report post`), onPress() { if (NEW_REPORT_DIALOG_ENABLED) { - openDialog(ReportDialog, {type: 'post', uri: postUri, cid: postCid}) + openDialog(ReportDialog, { + type: 'content', + uri: postUri, + cid: postCid, + }) } else { openModal({ name: 'report',