From 8b3bfb3cf7459af59fb4535241a6251e35e88eb9 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 17 May 2024 17:56:58 -0500 Subject: [PATCH] Make generic convo report dialog (#4085) --- .../ReportDialog/SelectReportOptionView.tsx | 9 +- src/components/ReportDialog/types.ts | 2 + src/components/dms/ConvoMenu.tsx | 7 +- src/components/dms/MessageMenu.tsx | 7 +- .../dms/MessagesListBlockedFooter.tsx | 7 +- .../dms/ReportConversationPrompt.tsx | 27 ----- ...ssageReportDialog.tsx => ReportDialog.tsx} | 106 +++++++++++++----- src/lib/moderation/useReportOptions.ts | 18 ++- 8 files changed, 117 insertions(+), 66 deletions(-) delete mode 100644 src/components/dms/ReportConversationPrompt.tsx rename src/components/dms/{MessageReportDialog.tsx => ReportDialog.tsx} (72%) diff --git a/src/components/ReportDialog/SelectReportOptionView.tsx b/src/components/ReportDialog/SelectReportOptionView.tsx index da3c434401..4053844768 100644 --- a/src/components/ReportDialog/SelectReportOptionView.tsx +++ b/src/components/ReportDialog/SelectReportOptionView.tsx @@ -25,12 +25,10 @@ import {SquareArrowTopRight_Stroke2_Corner0_Rounded as SquareArrowTopRight} from import {Text} from '#/components/Typography' import {ReportDialogProps} from './types' -type ParamsWithMessages = ReportDialogProps['params'] | {type: 'message'} - export function SelectReportOptionView({ ...props }: { - params: ParamsWithMessages + params: ReportDialogProps['params'] labelers: AppBskyLabelerDefs.LabelerViewDetailed[] onSelectReportOption: (reportOption: ReportOption) => void goBack: () => void @@ -57,9 +55,12 @@ export function SelectReportOptionView({ } else if (props.params.type === 'feedgen') { title = _(msg`Report this feed`) description = _(msg`Why should this feed be reviewed?`) - } else if (props.params.type === 'message') { + } else if (props.params.type === 'convoMessage') { title = _(msg`Report this message`) description = _(msg`Why should this message be reviewed?`) + } else if (props.params.type === 'convoAccount') { + title = _(msg`Report this account`) + description = _(msg`Why should this account be reviewed?`) } return { diff --git a/src/components/ReportDialog/types.ts b/src/components/ReportDialog/types.ts index 0c8a1e0778..5a13856520 100644 --- a/src/components/ReportDialog/types.ts +++ b/src/components/ReportDialog/types.ts @@ -12,4 +12,6 @@ export type ReportDialogProps = { type: 'account' did: string } + | {type: 'convoMessage'} + | {type: 'convoAccount'} } diff --git a/src/components/dms/ConvoMenu.tsx b/src/components/dms/ConvoMenu.tsx index 0e5cd12bf8..50a5280849 100644 --- a/src/components/dms/ConvoMenu.tsx +++ b/src/components/dms/ConvoMenu.tsx @@ -21,7 +21,7 @@ import * as Toast from '#/view/com/util/Toast' import {atoms as a, useTheme} from '#/alf' import {BlockedByListDialog} from '#/components/dms/BlockedByListDialog' import {LeaveConvoPrompt} from '#/components/dms/LeaveConvoPrompt' -import {ReportConversationPrompt} from '#/components/dms/ReportConversationPrompt' +import {ReportDialog} from '#/components/dms/ReportDialog' import {ArrowBoxLeft_Stroke2_Corner0_Rounded as ArrowBoxLeft} from '#/components/icons/ArrowBoxLeft' import {DotGrid_Stroke2_Corner0_Rounded as DotsHorizontal} from '#/components/icons/DotGrid' import {Flag_Stroke2_Corner0_Rounded as Flag} from '#/components/icons/Flag' @@ -205,7 +205,10 @@ let ConvoMenu = ({ convoId={convo.id} currentScreen={currentScreen} /> - + - + - + {}} - showCancel={false} - /> - ) -} diff --git a/src/components/dms/MessageReportDialog.tsx b/src/components/dms/ReportDialog.tsx similarity index 72% rename from src/components/dms/MessageReportDialog.tsx rename to src/components/dms/ReportDialog.tsx index cc25732afb..e8ac0ed2fe 100644 --- a/src/components/dms/MessageReportDialog.tsx +++ b/src/components/dms/ReportDialog.tsx @@ -25,12 +25,24 @@ import {RichText} from '../RichText' import {Text} from '../Typography' import {MessageItemMetadata} from './MessageItem' -let MessageReportDialog = ({ +type ReportDialogParams = + | { + type: 'convoAccount' + did: string + convoId: string + } + | { + type: 'convoMessage' + convoId: string + message: ChatBskyConvoDefs.MessageView + } + +let ReportDialog = ({ control, - message, + params, }: { control: Dialog.DialogControlProps - message: ChatBskyConvoDefs.MessageView + params: ReportDialogParams }): React.ReactNode => { const {_} = useLingui() return ( @@ -39,33 +51,35 @@ let MessageReportDialog = ({ nativeOptions={isAndroid ? {sheet: {snapPoints: ['100%']}} : {}}> - + ) } -MessageReportDialog = memo(MessageReportDialog) -export {MessageReportDialog} +ReportDialog = memo(ReportDialog) +export {ReportDialog} -function DialogInner({message}: {message: ChatBskyConvoDefs.MessageView}) { +function DialogInner({params}: {params: ReportDialogParams}) { const [reportOption, setReportOption] = useState(null) return reportOption ? ( setReportOption(null)} /> ) : ( - + ) } function ReasonStep({ setReportOption, + params, }: { setReportOption: (reportOption: ReportOption) => void + params: ReportDialogParams }) { const control = Dialog.useDialogContext() @@ -73,18 +87,26 @@ function ReasonStep({ ) } function SubmitStep({ - message, + params, reportOption, goBack, }: { - message: ChatBskyConvoDefs.MessageView + params: ReportDialogParams reportOption: ReportOption goBack: () => void }) { @@ -101,17 +123,33 @@ function SubmitStep({ isPending: submitting, } = useMutation({ mutationFn: async () => { - const report = { - reasonType: reportOption.reason, - subject: { - $type: 'chat.bsky.convo.defs#messageRef', - messageId: message.id, - did: message.sender!.did, - } satisfies ChatBskyConvoDefs.MessageRef, - reason: details, - } satisfies ComAtprotoModerationCreateReport.InputSchema + if (params.type === 'convoMessage') { + const {convoId, message} = params + + const report = { + reasonType: reportOption.reason, + subject: { + $type: 'chat.bsky.convo.defs#messageRef', + messageId: message.id, + convoId, + did: message.sender.did, + } satisfies ChatBskyConvoDefs.MessageRef, + reason: details, + } satisfies ComAtprotoModerationCreateReport.InputSchema + + await getAgent().createModerationReport(report) + } else if (params.type === 'convoAccount') { + const {convoId, did} = params - await getAgent().createModerationReport(report) + await getAgent().createModerationReport({ + reasonType: reportOption.reason, + subject: { + $type: 'com.atproto.admin.defs#repoRef', + did, + }, + reason: details + ` — from:dms:${convoId}`, + }) + } }, onSuccess: () => { control.close(() => { @@ -120,6 +158,17 @@ function SubmitStep({ }, }) + const copy = useMemo(() => { + return { + convoMessage: { + title: _(msg`Report this message`), + }, + convoAccount: { + title: _(msg`Report this account`), + }, + }[params.type] + }, [_, params]) + return (