diff --git a/src/components/moderation/ReportDialog/utils/useReportOptions.ts b/src/components/moderation/ReportDialog/utils/useReportOptions.ts index b4a203378..bb8aa715b 100644 --- a/src/components/moderation/ReportDialog/utils/useReportOptions.ts +++ b/src/components/moderation/ReportDialog/utils/useReportOptions.ts @@ -1,6 +1,5 @@ import {useMemo} from 'react' -import {msg} from '@lingui/core/macro' -import {useLingui} from '@lingui/react' +import {useLingui} from '@lingui/react/macro' import {tools} from '#/lexicons' @@ -27,221 +26,219 @@ export type ReportOption = { } export function useReportOptions() { - const {_} = useLingui() + const {t: l} = useLingui() return useMemo(() => { const categories: Record = { misleading: { key: 'misleading', - title: _(msg`Misleading`), - description: _(msg`Spam or other inauthentic behavior or deception`), + title: l`Misleading`, + description: l`Spam or other inauthentic behavior or deception`, options: [ { - title: _(msg`Spam`), + title: l`Spam`, reason: tools.ozone.report.defs.reasonMisleadingSpam.value, }, { - title: _(msg`Scam`), + title: l`Scam`, reason: tools.ozone.report.defs.reasonMisleadingScam.value, }, { - title: _(msg`Fake account or bot`), + title: l`Fake account or bot`, reason: tools.ozone.report.defs.reasonMisleadingBot.value, }, { - title: _(msg`Impersonation`), + title: l`Impersonation`, reason: tools.ozone.report.defs.reasonMisleadingImpersonation.value, }, { - title: _(msg`False information about elections`), + title: l`False information about elections`, reason: tools.ozone.report.defs.reasonMisleadingElections.value, }, { - title: _(msg`Other misleading content`), + title: l`Other misleading content`, reason: tools.ozone.report.defs.reasonMisleadingOther.value, }, ], }, sexualAdultContent: { key: 'sexualAdultContent', - title: _(msg`Adult content`), - description: _( - msg`Unlabeled, abusive, or non-consensual adult content`, - ), + title: l`Adult content`, + description: l`Unlabeled, abusive, or non-consensual adult content`, options: [ { - title: _(msg`Unlabeled adult content`), + title: l`Unlabeled adult content`, reason: tools.ozone.report.defs.reasonSexualUnlabeled.value, }, { - title: _(msg`Adult sexual abuse content`), + title: l`Adult sexual abuse content`, reason: tools.ozone.report.defs.reasonSexualAbuseContent.value, }, { - title: _(msg`Non-consensual intimate imagery`), + title: l`Non-consensual intimate imagery`, reason: tools.ozone.report.defs.reasonSexualNCII.value, }, { - title: _(msg`Deepfake adult content`), + title: l`Deepfake adult content`, reason: tools.ozone.report.defs.reasonSexualDeepfake.value, }, { - title: _(msg`Animal sexual abuse`), + title: l`Animal sexual abuse`, reason: tools.ozone.report.defs.reasonSexualAnimal.value, }, { - title: _(msg`Other sexual violence content`), + title: l`Other sexual violence content`, reason: tools.ozone.report.defs.reasonSexualOther.value, }, ], }, harassmentHate: { key: 'harassmentHate', - title: _(msg`Harassment or hate`), - description: _(msg`Abusive or discriminatory behavior`), + title: l`Harassment or hate`, + description: l`Abusive or discriminatory behavior`, options: [ { - title: _(msg`Trolling`), + title: l`Trolling`, reason: tools.ozone.report.defs.reasonHarassmentTroll.value, }, { - title: _(msg`Targeted harassment`), + title: l`Targeted harassment`, reason: tools.ozone.report.defs.reasonHarassmentTargeted.value, }, { - title: _(msg`Hate speech`), + title: l`Hate speech`, reason: tools.ozone.report.defs.reasonHarassmentHateSpeech.value, }, { - title: _(msg`Doxxing`), + title: l`Doxxing`, reason: tools.ozone.report.defs.reasonHarassmentDoxxing.value, }, { - title: _(msg`Other harassing or hateful content`), + title: l`Other harassing or hateful content`, reason: tools.ozone.report.defs.reasonHarassmentOther.value, }, ], }, violencePhysicalHarm: { key: 'violencePhysicalHarm', - title: _(msg`Violence`), - description: _(msg`Violent or threatening content`), + title: l`Violence`, + description: l`Violent or threatening content`, options: [ { - title: _(msg`Animal welfare`), + title: l`Animal welfare`, reason: tools.ozone.report.defs.reasonViolenceAnimal.value, }, { - title: _(msg`Threats or incitement`), + title: l`Threats or incitement`, reason: tools.ozone.report.defs.reasonViolenceThreats.value, }, { - title: _(msg`Graphic violent content`), + title: l`Graphic violent content`, reason: tools.ozone.report.defs.reasonViolenceGraphicContent.value, }, { - title: _(msg`Glorification of violence`), + title: l`Glorification of violence`, reason: tools.ozone.report.defs.reasonViolenceGlorification.value, }, { - title: _(msg`Extremist content`), + title: l`Extremist content`, reason: tools.ozone.report.defs.reasonViolenceExtremistContent.value, }, { - title: _(msg`Human trafficking`), + title: l`Human trafficking`, reason: tools.ozone.report.defs.reasonViolenceTrafficking.value, }, { - title: _(msg`Other violent content`), + title: l`Other violent content`, reason: tools.ozone.report.defs.reasonViolenceOther.value, }, ], }, childSafety: { key: 'childSafety', - title: _(msg`Child safety`), - description: _(msg`Harming or endangering minors`), + title: l`Child safety`, + description: l`Harming or endangering minors`, options: [ { - title: _(msg`Child Sexual Abuse Material (CSAM)`), + title: l`Child Sexual Abuse Material (CSAM)`, reason: tools.ozone.report.defs.reasonChildSafetyCSAM.value, }, { - title: _(msg`Grooming or predatory behavior`), + title: l`Grooming or predatory behavior`, reason: tools.ozone.report.defs.reasonChildSafetyGroom.value, }, { - title: _(msg`Privacy violation of a minor`), + title: l`Privacy violation of a minor`, reason: tools.ozone.report.defs.reasonChildSafetyPrivacy.value, }, { - title: _(msg`Minor harassment or bullying`), + title: l`Minor harassment or bullying`, reason: tools.ozone.report.defs.reasonChildSafetyHarassment.value, }, { - title: _(msg`Other child safety issue`), + title: l`Other child safety issue`, reason: tools.ozone.report.defs.reasonChildSafetyOther.value, }, ], }, selfHarm: { key: 'selfHarm', - title: _(msg`Self-harm or dangerous behaviors`), - description: _(msg`Harmful or high-risk activities`), + title: l`Self-harm or dangerous behaviors`, + description: l`Harmful or high-risk activities`, options: [ { - title: _(msg`Content promoting or depicting self-harm`), + title: l`Content promoting or depicting self-harm`, reason: tools.ozone.report.defs.reasonSelfHarmContent.value, }, { - title: _(msg`Eating disorders`), + title: l`Eating disorders`, reason: tools.ozone.report.defs.reasonSelfHarmED.value, }, { - title: _(msg`Dangerous challenges or activities`), + title: l`Dangerous challenges or activities`, reason: tools.ozone.report.defs.reasonSelfHarmStunts.value, }, { - title: _(msg`Dangerous substances or drug abuse`), + title: l`Dangerous substances or drug abuse`, reason: tools.ozone.report.defs.reasonSelfHarmSubstances.value, }, { - title: _(msg`Other dangerous content`), + title: l`Other dangerous content`, reason: tools.ozone.report.defs.reasonSelfHarmOther.value, }, ], }, ruleBreaking: { key: 'ruleBreaking', - title: _(msg`Breaking site rules`), - description: _(msg`Banned activities or security violations`), + title: l`Breaking site rules`, + description: l`Banned activities or security violations`, options: [ { - title: _(msg`Hacking or system attacks`), + title: l`Hacking or system attacks`, reason: tools.ozone.report.defs.reasonRuleSiteSecurity.value, }, { - title: _(msg`Promoting or selling prohibited items or services`), + title: l`Promoting or selling prohibited items or services`, reason: tools.ozone.report.defs.reasonRuleProhibitedSales.value, }, { - title: _(msg`Banned user returning`), + title: l`Banned user returning`, reason: tools.ozone.report.defs.reasonRuleBanEvasion.value, }, { - title: _(msg`Other network rule-breaking`), + title: l`Other network rule-breaking`, reason: tools.ozone.report.defs.reasonRuleOther.value, }, ], }, other: { key: 'other', - title: _(msg`Other`), - description: _(msg`An issue not included in these options`), + title: l`Other`, + description: l`An issue not included in these options`, options: [ { - title: _(msg`Other`), + title: l`Other`, reason: tools.ozone.report.defs.reasonOther.value, }, ], @@ -254,5 +251,5 @@ export function useReportOptions() { return categories[reasonName] }, } - }, [_]) + }, [l]) } diff --git a/src/lib/routes/types.ts b/src/lib/routes/types.ts index 4f52f0b43..a115fa480 100644 --- a/src/lib/routes/types.ts +++ b/src/lib/routes/types.ts @@ -27,7 +27,7 @@ export type CommonNavigatorParams = { Moderation: undefined ModerationInbox: {tab?: ModerationInboxTab} ModerationInboxSettings: undefined - ModerationInboxReportDetails: undefined + ModerationInboxReportDetails: {moderationService: string; id: string} ModerationInboxNoticeDetails: undefined ModerationModlists: undefined ModerationMutedAccounts: undefined diff --git a/src/routes.ts b/src/routes.ts index 44866e866..ad910f7f4 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -20,7 +20,8 @@ export const router = new Router({ Moderation: '/moderation', ModerationInbox: '/moderation/inbox', ModerationInboxSettings: '/moderation/inbox/settings', - ModerationInboxReportDetails: '/moderation/inbox/report/details', + ModerationInboxReportDetails: + '/moderation/inbox/report/:moderationService/:id', ModerationInboxNoticeDetails: '/moderation/inbox/notice/details', ModerationModlists: '/moderation/modlists', ModerationMutedAccounts: '/moderation/muted-accounts', diff --git a/src/screens/ModerationInbox/Report.tsx b/src/screens/ModerationInbox/Report.tsx index 1d2cfbd91..bd0d51bb4 100644 --- a/src/screens/ModerationInbox/Report.tsx +++ b/src/screens/ModerationInbox/Report.tsx @@ -1,31 +1,80 @@ import {View} from 'react-native' +import {isValidDid} from '@atproto/syntax' +import {moderateProfile} from '@bsky/sdk/moderation' import {Trans, useLingui} from '@lingui/react/macro' +import {isAppLabeler} from '#/lib/moderation' +import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name' +import { + type CommonNavigatorParams, + type NativeStackScreenProps, +} from '#/lib/routes/types' +import {cleanError} from '#/lib/strings/errors' +import {matchXrpcError} from '#/lib/xrpc-error' +import {useModerationOpts} from '#/state/preferences/moderation-opts' +import {useLabelerInfoQuery} from '#/state/queries/labeler' +import {useModerationInboxReportQuery} from '#/state/queries/moderation-inbox' +import {ErrorMessage} from '#/view/com/util/error/ErrorMessage' import {NotFoundScreen} from '#/view/screens/NotFound' import {atoms as a, useTheme} from '#/alf' import * as Layout from '#/components/Layout' -import {InlineLinkText} from '#/components/Link' +import {Loader} from '#/components/Loader' +import {useReportOptions} from '#/components/moderation/ReportDialog/utils/useReportOptions' import {Text} from '#/components/Typography' import {useAnalytics} from '#/analytics' -import {ActionSummaryText} from './components/ActionSummaryText' +import {com, tools} from '#/lexicons' import {ContentBlock} from './components/ContentBlock' -import {SubjectPreview} from './components/SubjectPreview' -import {Timeline} from './components/Timeline' +import {ReportActionSummary} from './components/ReportActionSummary' +import {ReportSubjectPreview} from './components/ReportSubjectPreview' -export function ModerationInboxReportDetailsScreen() { +export function ModerationInboxReportDetailsScreen({ + route, +}: NativeStackScreenProps< + CommonNavigatorParams, + 'ModerationInboxReportDetails' +>) { const t = useTheme() const {t: l} = useLingui() const ax = useAnalytics() - + const moderationOpts = useModerationOpts() const isEnabled = ax.features.enabled(ax.features.ModerationInboxEnable) + const moderationService = isValidDid(route.params.moderationService) + ? route.params.moderationService + : undefined + const parsedId = Number(route.params.id) + const id = + Number.isSafeInteger(parsedId) && parsedId > 0 ? parsedId : undefined + const reportQuery = useModerationInboxReportQuery({ + moderationService, + id, + enabled: isEnabled, + }) + const {data: labeler} = useLabelerInfoQuery({ + did: moderationService, + enabled: isEnabled && id !== undefined, + }) + const serviceName = + labeler && moderationOpts + ? createSanitizedDisplayName( + labeler.creator, + false, + moderateProfile(labeler.creator, moderationOpts).ui('displayName'), + ) + : moderationService && isAppLabeler(moderationService) + ? l`Bluesky Moderation Service` + : moderationService + const isLoading = !reportQuery.isError && !reportQuery.data - if (!isEnabled) { + if ( + !isEnabled || + !moderationService || + id === undefined || + matchXrpcError(reportQuery.error, tools.ozone.inbox.getReport) === + 'NotFound' + ) { return } - // TODO This is a placeholder value. -dsb - const note = 'Lorem ipsum dolor sit amet.' - return ( @@ -35,66 +84,104 @@ export function ModerationInboxReportDetailsScreen() { Your report - Bluesky Moderation Service + + {serviceName} + - - - - - The post you reported has been restored after another review. If - you’d rather not see it, you can mute or block the account. Read - our{' '} - - Community Guidelines - - . - - + + {reportQuery.isError ? ( + void reportQuery.refetch()} + /> + ) : reportQuery.data ? ( + + ) : ( + + + + )} + + + ) +} - - +function ReportDetails({ + data: {report, resolution}, +}: { + data: tools.ozone.inbox.getReport.$OutputBody +}) { + const t = useTheme() + const {t: l} = useLingui() + const {categories, getCategory} = useReportOptions() + const reasonType = + report.reasonType === com.atproto.moderation.defs.reasonSpam.value + ? tools.ozone.report.defs.reasonMisleadingSpam.value + : report.reasonType + const selectedReason = categories + .flatMap(category => category.options) + .find(option => option.reason === reasonType) + const fallbackReasonLabels = new Map([ + [ + com.atproto.moderation.defs.reasonViolation.value, + getCategory('ruleBreaking').title, + ], + [ + com.atproto.moderation.defs.reasonMisleading.value, + getCategory('misleading').title, + ], + [ + com.atproto.moderation.defs.reasonSexual.value, + getCategory('sexualAdultContent').title, + ], + [ + com.atproto.moderation.defs.reasonRude.value, + getCategory('harassmentHate').title, + ], + [com.atproto.moderation.defs.reasonOther.value, getCategory('other').title], + [com.atproto.moderation.defs.reasonAppeal.value, l`Appeal`], + [tools.ozone.report.defs.reasonAppeal.value, l`Appeal`], + ]) + const reasonLabel = + selectedReason?.title ?? + fallbackReasonLabels.get(report.reasonType) ?? + l`Unknown report reason` + const note = report.reason - - - Reason: - - - Spam - - + return ( + + - - - Your note: - - - “{note}” - - - + + - + + + Reason: + + + {reasonLabel} + - - + + {note ? ( + + + Your note: + + + “{note}” + + + ) : null} + + ) } diff --git a/src/screens/ModerationInbox/components/ActionSummaryText.tsx b/src/screens/ModerationInbox/components/ActionSummaryText.tsx index 5d03793dc..ae5e0bf84 100644 --- a/src/screens/ModerationInbox/components/ActionSummaryText.tsx +++ b/src/screens/ModerationInbox/components/ActionSummaryText.tsx @@ -1,4 +1,5 @@ import {View} from 'react-native' +import {useLingui} from '@lingui/react/macro' import {atoms as a, useTheme} from '#/alf' import {H1, Text} from '#/components/Typography' @@ -6,8 +7,10 @@ import {H1, Text} from '#/components/Typography' export function ActionSummaryText({ header, children, -}: React.PropsWithChildren<{header: string}>) { + date, +}: React.PropsWithChildren<{header: string; date?: Date}>) { const t = useTheme() + const {i18n} = useLingui() // Cleaner to call this ActionSummaryText and suppress lint in one location vs every call site. // oxlint-disable-next-line bsky-internal/avoid-unwrapped-text @@ -18,7 +21,14 @@ export function ActionSummaryText({ style={[a.text_xl, a.font_semi_bold, a.leading_tight]}> {header} - {children} + {children ? ( + {children} + ) : null} + {date ? ( + + {i18n.date(date, {dateStyle: 'medium', timeStyle: 'short'})} + + ) : null} ) } diff --git a/src/screens/ModerationInbox/components/ReportActionSummary.tsx b/src/screens/ModerationInbox/components/ReportActionSummary.tsx new file mode 100644 index 000000000..dd2866f9b --- /dev/null +++ b/src/screens/ModerationInbox/components/ReportActionSummary.tsx @@ -0,0 +1,162 @@ +import {AtUri, isAtUriString} from '@atproto/syntax' +import {Trans, useLingui} from '@lingui/react/macro' + +import {webLinks} from '#/lib/constants' +import {atoms as a} from '#/alf' +import {InlineLinkText} from '#/components/Link' +import {type tools} from '#/lexicons' +import {ActionSummaryText} from './ActionSummaryText' +import {getReportActionLabel} from './util/reportActionLabel' + +export function ReportActionSummary({ + report, + resolution, +}: tools.ozone.inbox.getReport.$OutputBody) { + const {i18n, t: l} = useLingui() + const isPost = + 'uri' in report.subject && + typeof report.subject.uri === 'string' && + isAtUriString(report.subject.uri, {strict: false}) && + new AtUri(report.subject.uri).collection === 'app.bsky.feed.post' + const noAction = resolution?.outcome === 'noAction' + const restored = + !noAction && + (resolution?.actionTaken === 'contentRestored' || + resolution?.actionTaken === 'accountRestored') + const actionTaken = + !noAction && + !restored && + (resolution?.outcome === 'actionTaken' || !!resolution?.actionTaken) + const actionLabel = getReportActionLabel({ + status: report.status, + lastActionTaken: resolution?.actionTaken, + resolutionOutcome: resolution?.outcome, + }) + const header = actionLabel ? i18n._(actionLabel) : undefined + const date = new Date( + resolution?.resolvedAt ?? + (report.status === 'resolved' ? report.updatedAt : report.createdAt), + ) + + if (!header) return null + + let description: React.ReactNode + + if (report.status === 'pending' && !resolution) { + description = ( + + Thanks for your report. We’ll look into it and take action in accordance + with our{' '} + + Community Guidelines + + . + + ) + } else if (restored && resolution?.actionTaken === 'accountRestored') { + description = ( + + The account you reported has been restored after another review. You can + mute or block it if you’d rather not see its content. Read our{' '} + + Community Guidelines + + . + + ) + } else if (restored) { + description = ( + + The content you reported has been restored after another review. If + you’d rather not see it, you can mute or block the account. Read our{' '} + + Community Guidelines + + . + + ) + } else if (isPost && noAction) { + description = ( + + We reviewed your report and found that this doesn’t break our rules. You + can mute or block the account if you’d rather not see the post. Read our{' '} + + Community Guidelines + + . + + ) + } else if (noAction) { + description = ( + + We reviewed your report and found that this doesn’t break our rules. + Read our{' '} + + Community Guidelines + + . + + ) + } else if (isPost && actionTaken) { + description = ( + + Thanks for helping keep Bluesky safe. This post violated our{' '} + + Community Guidelines + + . + + ) + } else if (actionTaken) { + description = ( + + Thanks for helping keep Bluesky safe. We reviewed your report and took + action. Read our{' '} + + Community Guidelines + + . + + ) + } else { + description = ( + + Your report has been resolved. Read our{' '} + + Community Guidelines + + . + + ) + } + + return ( + + {description} + + ) +} diff --git a/src/screens/ModerationInbox/components/ReportSubjectPreview/AccountSubjectPreview.tsx b/src/screens/ModerationInbox/components/ReportSubjectPreview/AccountSubjectPreview.tsx new file mode 100644 index 000000000..a47638a43 --- /dev/null +++ b/src/screens/ModerationInbox/components/ReportSubjectPreview/AccountSubjectPreview.tsx @@ -0,0 +1,63 @@ +import {View} from 'react-native' +import {Trans, useLingui} from '@lingui/react/macro' + +import {UserAvatar} from '#/view/com/util/UserAvatar' +import {useSubjectPreviewProfile} from '#/screens/ModerationInbox/components/hooks/useSubjectPreviewProfile' +import {atoms as a} from '#/alf' +import {Text} from '#/components/Typography' +import {PreviewContent} from './PreviewContent' + +export function AccountSubjectPreview({did}: {did: string}) { + const {i18n, t: l} = useLingui() + const {query, profile, moderation, name, handle} = + useSubjectPreviewProfile(did) + let content: React.ReactNode + const metadataText: string[] = [] + + if (profile && moderation) { + content = ( + + + {handle ? ( + + {handle} + + ) : null} + + ) + if (profile.createdAt) { + const createdAt = i18n.date(new Date(profile.createdAt), { + dateStyle: 'medium', + }) + metadataText.push(l`Joined ${createdAt}`) + } + } else { + content = ( + + Account unavailable + + ) + } + + return ( + + {content} + + ) +} diff --git a/src/screens/ModerationInbox/components/ReportSubjectPreview/ChatSubjectPreview.tsx b/src/screens/ModerationInbox/components/ReportSubjectPreview/ChatSubjectPreview.tsx new file mode 100644 index 000000000..d8838db91 --- /dev/null +++ b/src/screens/ModerationInbox/components/ReportSubjectPreview/ChatSubjectPreview.tsx @@ -0,0 +1,32 @@ +import {useLingui} from '@lingui/react/macro' + +import {useReportSubjectLabel} from '#/screens/ModerationInbox/components/hooks/useReportSubjectLabel' +import {type tools} from '#/lexicons' +import {PreviewContent} from './PreviewContent' + +export function ChatSubjectPreview({ + report, +}: { + report: tools.ozone.inbox.getReport.$OutputBody['report'] +}) { + const {t: l} = useLingui() + const title = useReportSubjectLabel(report.subject) + const conversation = + 'convoId' in report.subject && typeof report.subject.convoId === 'string' + ? report.subject.convoId + : undefined + + return ( + + ) +} diff --git a/src/screens/ModerationInbox/components/ReportSubjectPreview/FeedSubjectPreview.tsx b/src/screens/ModerationInbox/components/ReportSubjectPreview/FeedSubjectPreview.tsx new file mode 100644 index 000000000..2e6a74a21 --- /dev/null +++ b/src/screens/ModerationInbox/components/ReportSubjectPreview/FeedSubjectPreview.tsx @@ -0,0 +1,85 @@ +import {type AtUri} from '@atproto/syntax' +import {moderateFeedGenerator} from '@bsky/sdk/moderation' +import {Trans, useLingui} from '@lingui/react/macro' + +import {sanitizeDisplayName} from '#/lib/strings/display-names' +import {useFeedSourceInfoQuery} from '#/state/queries/feed' +import {useSubjectPreviewProfile} from '#/screens/ModerationInbox/components/hooks/useSubjectPreviewProfile' +import {atoms as a} from '#/alf' +import {Text} from '#/components/Typography' +import {app, type tools} from '#/lexicons' +import * as bsky from '#/types/bsky' +import {PreviewContent} from './PreviewContent' + +export function FeedSubjectPreview({ + report, + uri, +}: { + report: tools.ozone.inbox.getReport.$OutputBody['report'] + uri: AtUri +}) { + const {i18n, t: l} = useLingui() + const query = useFeedSourceInfoQuery({uri: uri.toString()}) + const { + opts, + name, + moderation: creatorModeration, + query: creatorQuery, + } = useSubjectPreviewProfile(uri.host) + const view = query.data?.type === 'feed' ? query.data.view : undefined + // A newer revision must not stand in for the reported feed. + const matches = + view && 'cid' in report.subject && view.cid === report.subject.cid + const record = bsky.matches(app.bsky.feed.generator, report.record) + ? report.record + : undefined + const moderation = + view && opts ? moderateFeedGenerator(view, opts) : creatorModeration + const available = !!matches && !!moderation + const feedName = available + ? (record?.displayName ?? view?.displayName) + : undefined + const title = feedName ? l`Feed “${sanitizeDisplayName(feedName)}”` : l`Feed` + const description = + record?.description ?? (matches ? view.description : undefined) + const metadataText = [l`By ${name}`] + if (record) { + const createdAt = i18n.date(new Date(record.createdAt), { + dateStyle: 'medium', + }) + metadataText.push(l`Created ${createdAt}`) + } + let content: React.ReactNode + if (!available) { + content = ( + + Feed unavailable + + ) + } else if (description) { + content = ( + + Description: “{description}” + + ) + } + + return ( + + {content} + + ) +} diff --git a/src/screens/ModerationInbox/components/ReportSubjectPreview/ListSubjectPreview.tsx b/src/screens/ModerationInbox/components/ReportSubjectPreview/ListSubjectPreview.tsx new file mode 100644 index 000000000..1d8361edf --- /dev/null +++ b/src/screens/ModerationInbox/components/ReportSubjectPreview/ListSubjectPreview.tsx @@ -0,0 +1,90 @@ +import {type AtUri} from '@atproto/syntax' +import {moderateUserList} from '@bsky/sdk/moderation' +import {plural} from '@lingui/core/macro' +import {Trans, useLingui} from '@lingui/react/macro' + +import {sanitizeDisplayName} from '#/lib/strings/display-names' +import {useListQuery} from '#/state/queries/list' +import {useSubjectPreviewProfile} from '#/screens/ModerationInbox/components/hooks/useSubjectPreviewProfile' +import {atoms as a} from '#/alf' +import {Text} from '#/components/Typography' +import {app, type tools} from '#/lexicons' +import * as bsky from '#/types/bsky' +import {PreviewContent} from './PreviewContent' + +export function ListSubjectPreview({ + report, + uri, +}: { + report: tools.ozone.inbox.getReport.$OutputBody['report'] + uri: AtUri +}) { + const {i18n, t: l} = useLingui() + const query = useListQuery(uri.toString()) + const { + opts, + name, + moderation: creatorModeration, + query: creatorQuery, + } = useSubjectPreviewProfile(uri.host) + const view = query.data + // A newer revision must not stand in for the reported list. + const matches = + view && 'cid' in report.subject && view.cid === report.subject.cid + const record = bsky.matches(app.bsky.graph.list, report.record) + ? report.record + : undefined + const moderation = + view && opts ? moderateUserList(view, opts) : creatorModeration + const available = !!matches && !!moderation + const listName = available ? (record?.name ?? view?.name) : undefined + const title = listName ? l`List “${sanitizeDisplayName(listName)}”` : l`List` + const description = + record?.description ?? (matches ? view.description : undefined) + const count = matches ? view.listItemCount : undefined + const createdAt = record?.createdAt + const metadataText: string[] = [] + if (count !== undefined) { + metadataText.push( + l`${plural(count, {one: '# account', other: '# accounts'})}`, + ) + } + metadataText.push(l`By ${name}`) + if (createdAt) { + const date = i18n.date(new Date(createdAt), {dateStyle: 'medium'}) + metadataText.push(l`Created ${date}`) + } + let content: React.ReactNode + if (!available) { + content = ( + + List unavailable + + ) + } else if (description) { + content = ( + + Description: “{description}” + + ) + } + + return ( + + {content} + + ) +} diff --git a/src/screens/ModerationInbox/components/ReportSubjectPreview/PostSubjectPreview.tsx b/src/screens/ModerationInbox/components/ReportSubjectPreview/PostSubjectPreview.tsx new file mode 100644 index 000000000..5672de7cd --- /dev/null +++ b/src/screens/ModerationInbox/components/ReportSubjectPreview/PostSubjectPreview.tsx @@ -0,0 +1,130 @@ +import {View} from 'react-native' +import {AtUri, isAtUriString} from '@atproto/syntax' +import {moderatePost, moderateProfile} from '@bsky/sdk/moderation' +import {Trans, useLingui} from '@lingui/react/macro' + +import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name' +import {useModerationOpts} from '#/state/preferences/moderation-opts' +import {usePostQuery} from '#/state/queries/post' +import {useProfileQuery} from '#/state/queries/profile' +import {atoms as a, useTheme} from '#/alf' +import {ButtonText} from '#/components/Button' +import {Link} from '#/components/Link' +import {Loader} from '#/components/Loader' +import {ContentHider} from '#/components/moderation/ContentHider' +import {PostAlerts} from '#/components/moderation/PostAlerts' +import {Text} from '#/components/Typography' +import {app, type tools} from '#/lexicons' +import * as bsky from '#/types/bsky' + +type Report = tools.ozone.inbox.getReport.$OutputBody['report'] + +export function PostSubjectPreview({ + report, + uri, + subjectLabel, +}: { + report: Report + uri: AtUri + subjectLabel: string +}) { + const t = useTheme() + const {i18n, t: l} = useLingui() + const moderationOpts = useModerationOpts() + const postQuery = usePostQuery(uri.toString()) + // Do not present an edited post as the content that was reported. + const post = + postQuery.data && + 'cid' in report.subject && + report.subject.cid === postQuery.data.cid + ? postQuery.data + : undefined + const record = bsky.matches(app.bsky.feed.post, report.record) + ? report.record + : post && bsky.matches(app.bsky.feed.post, post.record) + ? post.record + : undefined + const parentUri = + record?.reply && isAtUriString(record.reply.parent.uri, {strict: false}) + ? new AtUri(record.reply.parent.uri) + : undefined + const {data: parentProfile} = useProfileQuery({did: parentUri?.host}) + const parentName = + parentProfile && moderationOpts + ? createSanitizedDisplayName( + parentProfile, + false, + moderateProfile(parentProfile, moderationOpts).ui('displayName'), + ) + : undefined + const moderation = + post && moderationOpts ? moderatePost(post, moderationOpts) : undefined + const title = + post && moderation && record?.reply + ? parentName + ? l`Reply to ${parentName}` + : l`Reply` + : subjectLabel + const isLoading = postQuery.isPending || (!!post && !moderationOpts) + + return ( + + + {title} + + {isLoading ? ( + + ) : post && record && moderation ? ( + <> + + + {record.text ? ( + + “{record.text}” + + ) : null} + + + + Posted{' '} + {i18n.date(new Date(record.createdAt), {dateStyle: 'medium'})} + + + + + + Open post + + + + + ) : ( + <> + + Post unavailable + + {record ? ( + + + Posted{' '} + {i18n.date(new Date(record.createdAt), {dateStyle: 'medium'})} + + + ) : null} + + )} + + ) +} diff --git a/src/screens/ModerationInbox/components/ReportSubjectPreview/PreviewContent.tsx b/src/screens/ModerationInbox/components/ReportSubjectPreview/PreviewContent.tsx new file mode 100644 index 000000000..8a789be94 --- /dev/null +++ b/src/screens/ModerationInbox/components/ReportSubjectPreview/PreviewContent.tsx @@ -0,0 +1,68 @@ +import {View} from 'react-native' +import {type ModerationUI} from '@bsky/sdk/moderation' + +import {atoms as a, useTheme} from '#/alf' +import {ButtonText} from '#/components/Button' +import {Link} from '#/components/Link' +import {Loader} from '#/components/Loader' +import {ContentHider} from '#/components/moderation/ContentHider' +import {Text} from '#/components/Typography' + +export function PreviewContent({ + testID, + title, + children, + metadataText = [], + loading = false, + moderation, + to, + openLabel, + openTestID = `${testID}Open`, +}: { + testID: string + title: string + children?: React.ReactNode + metadataText?: string[] + loading?: boolean + moderation?: ModerationUI + to?: React.ComponentProps['to'] + openLabel?: string + openTestID?: string +}) { + const t = useTheme() + + return ( + + + + {title} + + {loading ? : children} + {!loading && metadataText.length ? ( + + {metadataText.map((text, index) => ( + + {text} + + ))} + + ) : null} + {!loading && to && openLabel ? ( + + + {openLabel} + + + ) : null} + + + ) +} diff --git a/src/screens/ModerationInbox/components/ReportSubjectPreview/StarterPackSubjectPreview.tsx b/src/screens/ModerationInbox/components/ReportSubjectPreview/StarterPackSubjectPreview.tsx new file mode 100644 index 000000000..d0d506ae2 --- /dev/null +++ b/src/screens/ModerationInbox/components/ReportSubjectPreview/StarterPackSubjectPreview.tsx @@ -0,0 +1,122 @@ +import {type AtUri} from '@atproto/syntax' +import {ModerationDecision} from '@bsky/sdk/moderation' +import {plural} from '@lingui/core/macro' +import {Trans, useLingui} from '@lingui/react/macro' + +import {sanitizeDisplayName} from '#/lib/strings/display-names' +import {useStarterPackQuery} from '#/state/queries/starter-packs' +import {useSubjectPreviewProfile} from '#/screens/ModerationInbox/components/hooks/useSubjectPreviewProfile' +import {atoms as a} from '#/alf' +import {Text} from '#/components/Typography' +import {app, type tools} from '#/lexicons' +import * as bsky from '#/types/bsky' +import {PreviewContent} from './PreviewContent' + +export function StarterPackSubjectPreview({ + report, + uri, +}: { + report: tools.ozone.inbox.getReport.$OutputBody['report'] + uri: AtUri +}) { + const {i18n, t: l} = useLingui() + const query = useStarterPackQuery({uri: uri.toString()}) + const { + opts: moderationOpts, + name: authorName, + moderation: creatorModeration, + query: creatorQuery, + } = useSubjectPreviewProfile(uri.host) + // Keep the preview tied to the reported record, not a later revision. + const starterPack = + query.data && + 'cid' in report.subject && + report.subject.cid === query.data.cid + ? query.data + : undefined + const record = bsky.matches(app.bsky.graph.starterpack, report.record) + ? report.record + : starterPack && + bsky.matches(app.bsky.graph.starterpack, starterPack.record) + ? starterPack.record + : undefined + const contentModeration = new ModerationDecision() + contentModeration.setDid(uri.host) + contentModeration.setIsMe(uri.host === moderationOpts?.userDid) + if (starterPack && moderationOpts) { + for (const label of starterPack.labels ?? []) { + contentModeration.addLabel('content', label, moderationOpts) + } + } + const moderation = ModerationDecision.merge( + contentModeration, + creatorModeration, + ) + const available = !!starterPack && !!record && !!moderationOpts + const name = available ? sanitizeDisplayName(record.name) : undefined + const title = name ? l`Starter Pack “${name}”` : l`Starter Pack` + const accountCount = starterPack?.list?.listItemCount ?? 0 + const feedCount = record?.feeds?.length ?? 0 + const isLoading = + query.isPending || + creatorQuery.isPending || + (!!starterPack && !moderationOpts) + const metadataText: string[] = [] + if (record) { + if (accountCount > 0 && feedCount > 0) { + metadataText.push( + l`${plural(accountCount, {one: '# account', other: '# accounts'})}, ${plural(feedCount, {one: '# feed', other: '# feeds'})}`, + ) + } else if (accountCount > 0) { + metadataText.push( + l`${plural(accountCount, {one: '# account', other: '# accounts'})}`, + ) + } else if (feedCount > 0) { + metadataText.push( + l`${plural(feedCount, {one: '# feed', other: '# feeds'})}`, + ) + } + } + if (authorName) { + metadataText.push(l`By ${authorName}`) + } + if (record) { + const createdAt = i18n.date(new Date(record.createdAt), { + dateStyle: 'medium', + }) + metadataText.push(l`Created ${createdAt}`) + } + + let content: React.ReactNode + if (!available) { + content = ( + + Starter pack unavailable + + ) + } else if (record?.description) { + content = ( + + Description: “{record.description}” + + ) + } + + return ( + + {content} + + ) +} diff --git a/src/screens/ModerationInbox/components/ReportSubjectPreview/StatusSubjectPreview.tsx b/src/screens/ModerationInbox/components/ReportSubjectPreview/StatusSubjectPreview.tsx new file mode 100644 index 000000000..aaabdc8c6 --- /dev/null +++ b/src/screens/ModerationInbox/components/ReportSubjectPreview/StatusSubjectPreview.tsx @@ -0,0 +1,77 @@ +import {type AtUri} from '@atproto/syntax' +import {moderateStatus} from '@bsky/sdk/moderation' +import {Trans, useLingui} from '@lingui/react/macro' + +import {useSubjectPreviewProfile} from '#/screens/ModerationInbox/components/hooks/useSubjectPreviewProfile' +import {atoms as a} from '#/alf' +import {Text} from '#/components/Typography' +import {app, type tools} from '#/lexicons' +import * as bsky from '#/types/bsky' +import {PreviewContent} from './PreviewContent' + +export function StatusSubjectPreview({ + report, + uri, +}: { + report: tools.ozone.inbox.getReport.$OutputBody['report'] + uri: AtUri +}) { + const {i18n, t: l} = useLingui() + const { + query, + profile, + name, + opts, + moderation: creatorModeration, + } = useSubjectPreviewProfile(uri.host) + const status = profile?.status + const matches = + status?.uri === uri.toString() && + 'cid' in report.subject && + status.cid === report.subject.cid && + !status.isDisabled + const moderation = + profile && matches && opts + ? moderateStatus(profile, opts) + : creatorModeration + const available = !!matches && !!moderation + const record = bsky.matches(app.bsky.actor.status, report.record) + ? report.record + : undefined + const metadataText = [l`Status by ${name}`] + if (record) { + const createdAt = i18n.date(new Date(record.createdAt), { + dateStyle: 'medium', + }) + metadataText.push(l`Set ${createdAt}`) + } + let title = l`Account status` + if (available && record?.status === app.bsky.actor.status.live.value) { + title = l`Live status` + if (record.embed && bsky.matches(app.bsky.embed.external, record.embed)) { + try { + const url = new URL(record.embed.external.uri) + if (url.protocol === 'https:' || url.protocol === 'http:') { + title = l`Live link: “${url.hostname}”` + } + } catch { + // Invalid embed URLs do not become navigation destinations. + } + } + } + + return ( + + {!available || !record ? ( + + Status unavailable + + ) : null} + + ) +} diff --git a/src/screens/ModerationInbox/components/ReportSubjectPreview/index.tsx b/src/screens/ModerationInbox/components/ReportSubjectPreview/index.tsx new file mode 100644 index 000000000..794150cea --- /dev/null +++ b/src/screens/ModerationInbox/components/ReportSubjectPreview/index.tsx @@ -0,0 +1,143 @@ +import {View} from 'react-native' +import {AtUri, isAtUriString} from '@atproto/syntax' +import {Trans, useLingui} from '@lingui/react/macro' + +import {useReportSubjectLabel} from '#/screens/ModerationInbox/components/hooks/useReportSubjectLabel' +import {atoms as a, useTheme} from '#/alf' +import {ButtonText} from '#/components/Button' +import {Link} from '#/components/Link' +import {Text} from '#/components/Typography' +import {type tools} from '#/lexicons' +import {AccountSubjectPreview} from './AccountSubjectPreview' +import {ChatSubjectPreview} from './ChatSubjectPreview' +import {FeedSubjectPreview} from './FeedSubjectPreview' +import {ListSubjectPreview} from './ListSubjectPreview' +import {PostSubjectPreview} from './PostSubjectPreview' +import {StarterPackSubjectPreview} from './StarterPackSubjectPreview' +import {StatusSubjectPreview} from './StatusSubjectPreview' + +type Report = tools.ozone.inbox.getReport.$OutputBody['report'] + +export function ReportSubjectPreview({report}: {report: Report}) { + const t = useTheme() + const {t: l} = useLingui() + const subjectLabel = useReportSubjectLabel(report.subject) + const uri = + 'uri' in report.subject && + typeof report.subject.uri === 'string' && + isAtUriString(report.subject.uri, {strict: false}) + ? new AtUri(report.subject.uri) + : undefined + const to = getSubjectLink(report.subject) + const openLabel = 'convoId' in report.subject ? l`Open chat` : l`Open content` + let preview: React.ReactNode + + if ('convoId' in report.subject) { + preview = + } else if ( + !uri && + 'did' in report.subject && + typeof report.subject.did === 'string' + ) { + preview = + } else { + switch (uri?.collection) { + case 'app.bsky.feed.post': + preview = ( + + ) + break + case 'app.bsky.graph.starterpack': + preview = + break + case 'app.bsky.feed.generator': + preview = + break + case 'app.bsky.graph.list': + preview = + break + case 'app.bsky.actor.status': + preview = + break + default: + preview = ( + <> + + {subjectLabel} + + + Content unavailable + + {to ? ( + + + {openLabel} + + + ) : null} + + ) + break + } + } + + return ( + + {preview} + + ) +} + +function getSubjectLink( + subject: Report['subject'], +): React.ComponentProps['to'] | undefined { + if ('convoId' in subject && typeof subject.convoId === 'string') { + return subject.convoId + ? { + screen: 'MessagesConversation', + params: {conversation: subject.convoId}, + } + : undefined + } + if ('did' in subject && typeof subject.did === 'string') { + return {screen: 'Profile', params: {name: subject.did}} + } + if ( + 'uri' in subject && + typeof subject.uri === 'string' && + isAtUriString(subject.uri, {strict: false}) + ) { + const uri = new AtUri(subject.uri) + const name = uri.host + const rkey = uri.rkey + switch (uri.collection) { + case 'app.bsky.feed.post': + return {screen: 'PostThread', params: {name, rkey}} + case 'app.bsky.graph.list': + return {screen: 'ProfileList', params: {name, rkey}} + case 'app.bsky.feed.generator': + return {screen: 'CustomFeed', params: {name, rkey}} + case 'app.bsky.graph.starterpack': + return {screen: 'StarterPack', params: {name, rkey}} + case 'app.bsky.actor.status': + return {screen: 'Profile', params: {name}} + } + } +} diff --git a/src/screens/ModerationInbox/components/YourReportRow.tsx b/src/screens/ModerationInbox/components/YourReportRow.tsx index abb31a150..5665e7731 100644 --- a/src/screens/ModerationInbox/components/YourReportRow.tsx +++ b/src/screens/ModerationInbox/components/YourReportRow.tsx @@ -22,7 +22,10 @@ export function YourReportRow({report}: {report: InboxReport}) { subject={subjectLabel} action={actionLabel ? i18n._(actionLabel) : undefined} date={new Date(report.updatedAt)} - to="/moderation/inbox/report/details" + to={{ + screen: 'ModerationInboxReportDetails', + params: {moderationService: report.src, id: report.id.toString()}, + }} unread={!report.isRead} /> diff --git a/src/screens/ModerationInbox/components/hooks/useReportSubjectLabel.ts b/src/screens/ModerationInbox/components/hooks/useReportSubjectLabel.ts index 9410d9843..d3d3d94c9 100644 --- a/src/screens/ModerationInbox/components/hooks/useReportSubjectLabel.ts +++ b/src/screens/ModerationInbox/components/hooks/useReportSubjectLabel.ts @@ -1,4 +1,4 @@ -import {AtUri} from '@atproto/syntax' +import {AtUri, isAtUriString} from '@atproto/syntax' import {moderateProfile} from '@bsky/sdk/moderation' import {useLingui} from '@lingui/react/macro' @@ -7,24 +7,20 @@ import {sanitizeDisplayName} from '#/lib/strings/display-names' import {useModerationOpts} from '#/state/preferences/moderation-opts' import {useProfileQuery} from '#/state/queries/profile' import {useStarterPackQuery} from '#/state/queries/starter-packs' -import {app, type tools} from '#/lexicons' +import {app} from '#/lexicons' import * as bsky from '#/types/bsky' import { getReportSubjectLabel, type ReportSubject, } from '../util/reportSubjectLabel' -type StarterPackRecord = - tools.ozone.inbox.getReport.$OutputBody['report']['record'] - -export function useReportSubjectLabel( - subject: ReportSubject, - record?: StarterPackRecord, -) { +export function useReportSubjectLabel(subject: ReportSubject) { const {i18n} = useLingui() const moderationOpts = useModerationOpts() const uri = - 'uri' in subject && typeof subject.uri === 'string' + 'uri' in subject && + typeof subject.uri === 'string' && + isAtUriString(subject.uri, {strict: false}) ? new AtUri(subject.uri) : undefined const subjectDid = @@ -33,18 +29,15 @@ export function useReportSubjectLabel( : undefined const collection = uri?.collection const isStarterPack = collection === 'app.bsky.graph.starterpack' - const embeddedStarterPackName = - record && bsky.isType(app.bsky.graph.starterpack, record) - ? sanitizeDisplayName(record.name) - : undefined const {data: starterPack} = useStarterPackQuery({ - uri: - isStarterPack && !embeddedStarterPackName && uri - ? uri.toString() - : undefined, + uri: isStarterPack ? uri?.toString() : undefined, }) const fetchedStarterPackName = - starterPack && bsky.isType(app.bsky.graph.starterpack, starterPack.record) + starterPack && + moderationOpts && + 'cid' in subject && + subject.cid === starterPack.cid && + bsky.matches(app.bsky.graph.starterpack, starterPack.record) ? sanitizeDisplayName(starterPack.record.name) : undefined const profileDid = @@ -63,7 +56,7 @@ export function useReportSubjectLabel( return i18n._( getReportSubjectLabel(subject, { authorName, - starterPackName: embeddedStarterPackName ?? fetchedStarterPackName, + starterPackName: fetchedStarterPackName, }), ) } diff --git a/src/screens/ModerationInbox/components/hooks/useSubjectPreviewProfile.ts b/src/screens/ModerationInbox/components/hooks/useSubjectPreviewProfile.ts new file mode 100644 index 000000000..896526294 --- /dev/null +++ b/src/screens/ModerationInbox/components/hooks/useSubjectPreviewProfile.ts @@ -0,0 +1,30 @@ +import {moderateProfile} from '@bsky/sdk/moderation' +import {useLingui} from '@lingui/react/macro' + +import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name' +import {sanitizeHandle} from '#/lib/strings/handles' +import {useModerationOpts} from '#/state/preferences/moderation-opts' +import {useProfileQuery} from '#/state/queries/profile' + +export function useSubjectPreviewProfile(did?: string) { + const {t: l} = useLingui() + const opts = useModerationOpts() + const query = useProfileQuery({did}) + const profile = query.data + const moderation = + profile && opts ? moderateProfile(profile, opts) : undefined + const name = + profile && moderation + ? createSanitizedDisplayName( + profile, + false, + moderation.ui('displayName'), + ) || l`Account` + : l`Account` + const handle = + profile && moderation && !moderation.ui('displayName').blur + ? sanitizeHandle(profile.handle, '@') + : undefined + + return {query, profile, opts, moderation, name, handle} +} diff --git a/src/screens/ModerationInbox/components/util/reportActionLabel.ts b/src/screens/ModerationInbox/components/util/reportActionLabel.ts index 65f9bac6f..2ee0ed2eb 100644 --- a/src/screens/ModerationInbox/components/util/reportActionLabel.ts +++ b/src/screens/ModerationInbox/components/util/reportActionLabel.ts @@ -24,10 +24,14 @@ export function getReportActionLabel({ switch (lastActionTaken) { case 'contentRemoved': return msg`Content removed` + case 'contentRestored': + return msg`Content restored` case 'accountSuspended': return msg`Account suspended` case 'accountTakedown': return msg`Account taken down` + case 'accountRestored': + return msg`Account restored` case 'labelApplied': return msg`Label applied` case 'labelRemoved': @@ -51,7 +55,9 @@ export function getReportActionLabel({ return msg`Awaiting review` } - if (status === 'resolved' || resolutionOutcome === 'other') { - return msg`Reviewed, no action taken` + if (status === 'resolved') { + return msg`Report resolved` } + + return undefined } diff --git a/src/screens/ModerationInbox/components/util/reportSubjectLabel.ts b/src/screens/ModerationInbox/components/util/reportSubjectLabel.ts index 997f5d4f6..115928737 100644 --- a/src/screens/ModerationInbox/components/util/reportSubjectLabel.ts +++ b/src/screens/ModerationInbox/components/util/reportSubjectLabel.ts @@ -1,4 +1,4 @@ -import {AtUri} from '@atproto/syntax' +import {AtUri, isAtUriString} from '@atproto/syntax' import {type MessageDescriptor} from '@lingui/core' import {msg} from '@lingui/core/macro' @@ -26,7 +26,11 @@ export function getReportSubjectLabel( return authorName ? msg`Conversation with ${authorName}` : msg`Conversation` } - if ('uri' in subject && typeof subject.uri === 'string') { + if ( + 'uri' in subject && + typeof subject.uri === 'string' && + isAtUriString(subject.uri, {strict: false}) + ) { switch (new AtUri(subject.uri).collection) { case 'app.bsky.feed.post': return authorName ? msg`Post by ${authorName}` : msg`Post` diff --git a/src/state/queries/moderation-inbox.ts b/src/state/queries/moderation-inbox.ts index 172d5e0d4..e1cb92d0d 100644 --- a/src/state/queries/moderation-inbox.ts +++ b/src/state/queries/moderation-inbox.ts @@ -1,3 +1,4 @@ +import {type DidString} from '@atproto/syntax' import {useLingui} from '@lingui/react/macro' import { useInfiniteQuery, @@ -49,6 +50,42 @@ export function useModerationInboxReportsQuery(filter: ReportsFilter) { }) } +export function useModerationInboxReportQuery({ + moderationService, + id, + enabled = true, +}: { + moderationService?: DidString + id?: number + enabled?: boolean +}) { + const client = useAppviewClient() + const {currentAccount, hasSession} = useSession() + const did = currentAccount?.did + + return useQuery({ + queryKey: createQueryKey(QUERY_KEY_ROOT, { + did, + endpoint: 'report', + moderationService, + id, + }), + queryFn: async () => { + if (!moderationService || id === undefined) { + throw new Error('Missing moderation service or report ID') + } + return await client.call( + tools.ozone.inbox.getReport, + {id}, + {service: `${moderationService}#atproto_labeler`}, + ) + }, + staleTime: STALE.MINUTES.ONE, + enabled: + enabled && hasSession && !!did && !!moderationService && id !== undefined, + }) +} + export function useModerationInboxActionedSubjectsQuery( filter: ActionedSubjectsFilter, ) {