Map to deprecated reason if necessary, send some reports only to Bluesky

This commit is contained in:
Eric Bailey
2025-10-03 15:57:43 -05:00
parent 53728b468b
commit 47aede964f
3 changed files with 46 additions and 11 deletions
@@ -9,6 +9,7 @@ import {useMutation} from '@tanstack/react-query'
import {logger} from '#/logger'
import {useAgent} from '#/state/session'
import {NEW_TO_OLD_REASONS_MAP} from './const'
import {type ReportState} from './state'
import {type ParsedReportSubject} from './types'
@@ -31,6 +32,26 @@ export function useSubmitReportMutation() {
throw new Error(_(msg`Please select a moderation service`))
}
const labeler = state.selectedLabeler
const labelerSupportedReasonTypes = labeler.reasonTypes || []
let reasonType = state.selectedOption.reason
const backwardsCompatableReasonType = NEW_TO_OLD_REASONS_MAP[reasonType]
const supportsNewReasonType =
labelerSupportedReasonTypes.includes(reasonType)
const supportsOldReasonType = labelerSupportedReasonTypes.includes(
backwardsCompatableReasonType,
)
/*
* Only fall back for backwards compatibility if the labeler
* does not support the new reason type. If the labeler does not declare
* supported reason types, send the new version.
*/
if (supportsOldReasonType && !supportsNewReasonType) {
reasonType = backwardsCompatableReasonType
}
let report:
| ComAtprotoModerationCreateReport.InputSchema
| (Omit<ComAtprotoModerationCreateReport.InputSchema, 'subject'> & {
@@ -40,7 +61,7 @@ export function useSubmitReportMutation() {
switch (subject.type) {
case 'account': {
report = {
reasonType: state.selectedOption.reason,
reasonType,
reason: state.details,
subject: {
$type: 'com.atproto.admin.defs#repoRef',
@@ -54,7 +75,7 @@ export function useSubmitReportMutation() {
case 'feed':
case 'starterPack': {
report = {
reasonType: state.selectedOption.reason,
reasonType,
reason: state.details,
subject: {
$type: 'com.atproto.repo.strongRef',
@@ -66,7 +87,7 @@ export function useSubmitReportMutation() {
}
case 'chatMessage': {
report = {
reasonType: state.selectedOption.reason,
reasonType,
reason: state.details,
subject: {
$type: 'chat.bsky.convo.defs#messageRef',
@@ -82,7 +103,7 @@ export function useSubmitReportMutation() {
if (__DEV__) {
logger.info('Submitting report', {
labeler: {
handle: state.selectedLabeler.creator.handle,
handle: labeler.creator.handle,
},
report,
})
@@ -90,7 +111,7 @@ export function useSubmitReportMutation() {
await agent.createModerationReport(report, {
encoding: 'application/json',
headers: {
'atproto-proxy': `${state.selectedLabeler.creator.did}#atproto_labeler`,
'atproto-proxy': `${labeler.creator.did}#atproto_labeler`,
},
})
}
@@ -116,10 +116,9 @@ export const OTHER_REPORT_REASONS: Set<OzoneReportDefs.ReasonType> = new Set([
])
/**
* Set of report reasons that should only be sent to moderation authorities,
* such as Bluesky.
* Set of report reasons that should only be sent Bluesky's moderation service.
*/
export const MOD_AUTHORITY_ONLY_REPORT_REASONS: Set<OzoneReportDefs.ReasonType> =
export const BSKY_LABELER_ONLY_REPORT_REASONS: Set<OzoneReportDefs.ReasonType> =
new Set([
OzoneReportDefs.REASONCHILDSAFETYCSAM,
OzoneReportDefs.REASONCHILDSAFETYGROOM,
@@ -1,7 +1,7 @@
import React from 'react'
import {Pressable, View} from 'react-native'
import {type ScrollView} from 'react-native-gesture-handler'
import {type AppBskyLabelerDefs} from '@atproto/api'
import {type AppBskyLabelerDefs, BSKY_LABELER_DID} from '@atproto/api'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
@@ -30,7 +30,11 @@ import {createStaticClick, InlineLinkText, Link} from '#/components/Link'
import {Loader} from '#/components/Loader'
import {Text} from '#/components/Typography'
import {useSubmitReportMutation} from './action'
import {SUPPORT_PAGE} from './const'
import {
BSKY_LABELER_ONLY_REPORT_REASONS,
NEW_TO_OLD_REASONS_MAP,
SUPPORT_PAGE,
} from './const'
import {useCopyForSubject} from './copy'
import {initialState, reducer} from './state'
import {type ReportDialogProps, type ReportSubject} from './types'
@@ -135,14 +139,25 @@ function Inner(props: ReportDialogProps) {
})
.filter(l => {
if (!state.selectedOption) return true
// some reasons ONLY go to Bluesky
if (BSKY_LABELER_ONLY_REPORT_REASONS.has(state.selectedOption.reason)) {
return l.creator.did === BSKY_LABELER_DID
}
const reasonTypes: string[] | undefined = l.reasonTypes
if (reasonTypes === undefined) return true
return reasonTypes.includes(state.selectedOption.reason)
return (
reasonTypes.includes(state.selectedOption.reason) ||
reasonTypes.includes(
NEW_TO_OLD_REASONS_MAP[state.selectedOption.reason],
)
)
})
}, [props, allLabelers, state.selectedOption])
const hasSupportedLabelers = !!supportedLabelers.length
const hasSingleSupportedLabeler = supportedLabelers.length === 1
console.log(supportedLabelers)
const onSubmit = React.useCallback(async () => {
dispatch({type: 'clearError'})