From 8b3bfb3cf7459af59fb4535241a6251e35e88eb9 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 17 May 2024 17:56:58 -0500 Subject: Make generic convo report dialog (#4085) --- src/components/dms/ReportDialog.tsx | 310 ++++++++++++++++++++++++++++++++++++ 1 file changed, 310 insertions(+) create mode 100644 src/components/dms/ReportDialog.tsx (limited to 'src/components/dms/ReportDialog.tsx') diff --git a/src/components/dms/ReportDialog.tsx b/src/components/dms/ReportDialog.tsx new file mode 100644 index 000000000..e8ac0ed2f --- /dev/null +++ b/src/components/dms/ReportDialog.tsx @@ -0,0 +1,310 @@ +import React, {memo, useMemo, useState} from 'react' +import {View} from 'react-native' +import { + ChatBskyConvoDefs, + ComAtprotoModerationCreateReport, + RichText as RichTextAPI, +} from '@atproto/api' +import {msg, Trans} from '@lingui/macro' +import {useLingui} from '@lingui/react' +import {useMutation} from '@tanstack/react-query' + +import {ReportOption} from '#/lib/moderation/useReportOptions' +import {isAndroid} from '#/platform/detection' +import {useAgent} from '#/state/session' +import {CharProgress} from '#/view/com/composer/char-progress/CharProgress' +import * as Toast from '#/view/com/util/Toast' +import {atoms as a, useBreakpoints, useTheme} from '#/alf' +import * as Dialog from '#/components/Dialog' +import {Button, ButtonIcon, ButtonText} from '../Button' +import {Divider} from '../Divider' +import {ChevronLeft_Stroke2_Corner0_Rounded as Chevron} from '../icons/Chevron' +import {Loader} from '../Loader' +import {SelectReportOptionView} from '../ReportDialog/SelectReportOptionView' +import {RichText} from '../RichText' +import {Text} from '../Typography' +import {MessageItemMetadata} from './MessageItem' + +type ReportDialogParams = + | { + type: 'convoAccount' + did: string + convoId: string + } + | { + type: 'convoMessage' + convoId: string + message: ChatBskyConvoDefs.MessageView + } + +let ReportDialog = ({ + control, + params, +}: { + control: Dialog.DialogControlProps + params: ReportDialogParams +}): React.ReactNode => { + const {_} = useLingui() + return ( + + + + + + + + ) +} +ReportDialog = memo(ReportDialog) +export {ReportDialog} + +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() + + return ( + + ) +} + +function SubmitStep({ + params, + reportOption, + goBack, +}: { + params: ReportDialogParams + reportOption: ReportOption + goBack: () => void +}) { + const {_} = useLingui() + const {gtMobile} = useBreakpoints() + const t = useTheme() + const [details, setDetails] = useState('') + const control = Dialog.useDialogContext() + const {getAgent} = useAgent() + + const { + mutate: submit, + error, + isPending: submitting, + } = useMutation({ + mutationFn: async () => { + 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({ + reasonType: reportOption.reason, + subject: { + $type: 'com.atproto.admin.defs#repoRef', + did, + }, + reason: details + ` — from:dms:${convoId}`, + }) + } + }, + onSuccess: () => { + control.close(() => { + Toast.show(_(msg`Thank you. Your report has been sent.`)) + }) + }, + }) + + const copy = useMemo(() => { + return { + convoMessage: { + title: _(msg`Report this message`), + }, + convoAccount: { + title: _(msg`Report this account`), + }, + }[params.type] + }, [_, params]) + + return ( + + + + + {copy.title} + + + Your report will be sent to the Bluesky Moderation Service + + + + + {params.type === 'convoMessage' && ( + + )} + + + + Reason: + {' '} + {reportOption.title} + + + + + + + Optionally provide additional information below: + + + + + + + + + + + + + {error && ( + + + There was an issue sending your report. Please check your internet + connection. + + + )} + + + + + ) +} + +function PreviewMessage({message}: {message: ChatBskyConvoDefs.MessageView}) { + const t = useTheme() + const rt = useMemo(() => { + return new RichTextAPI({text: message.text, facets: message.facets}) + }, [message.text, message.facets]) + + return ( + + + + + + + ) +} -- cgit 1.4.1