Map to deprecated reason if necessary, send some reports only to Bluesky
This commit is contained in:
@@ -9,6 +9,7 @@ import {useMutation} from '@tanstack/react-query'
|
|||||||
|
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
|
import {NEW_TO_OLD_REASONS_MAP} from './const'
|
||||||
import {type ReportState} from './state'
|
import {type ReportState} from './state'
|
||||||
import {type ParsedReportSubject} from './types'
|
import {type ParsedReportSubject} from './types'
|
||||||
|
|
||||||
@@ -31,6 +32,26 @@ export function useSubmitReportMutation() {
|
|||||||
throw new Error(_(msg`Please select a moderation service`))
|
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:
|
let report:
|
||||||
| ComAtprotoModerationCreateReport.InputSchema
|
| ComAtprotoModerationCreateReport.InputSchema
|
||||||
| (Omit<ComAtprotoModerationCreateReport.InputSchema, 'subject'> & {
|
| (Omit<ComAtprotoModerationCreateReport.InputSchema, 'subject'> & {
|
||||||
@@ -40,7 +61,7 @@ export function useSubmitReportMutation() {
|
|||||||
switch (subject.type) {
|
switch (subject.type) {
|
||||||
case 'account': {
|
case 'account': {
|
||||||
report = {
|
report = {
|
||||||
reasonType: state.selectedOption.reason,
|
reasonType,
|
||||||
reason: state.details,
|
reason: state.details,
|
||||||
subject: {
|
subject: {
|
||||||
$type: 'com.atproto.admin.defs#repoRef',
|
$type: 'com.atproto.admin.defs#repoRef',
|
||||||
@@ -54,7 +75,7 @@ export function useSubmitReportMutation() {
|
|||||||
case 'feed':
|
case 'feed':
|
||||||
case 'starterPack': {
|
case 'starterPack': {
|
||||||
report = {
|
report = {
|
||||||
reasonType: state.selectedOption.reason,
|
reasonType,
|
||||||
reason: state.details,
|
reason: state.details,
|
||||||
subject: {
|
subject: {
|
||||||
$type: 'com.atproto.repo.strongRef',
|
$type: 'com.atproto.repo.strongRef',
|
||||||
@@ -66,7 +87,7 @@ export function useSubmitReportMutation() {
|
|||||||
}
|
}
|
||||||
case 'chatMessage': {
|
case 'chatMessage': {
|
||||||
report = {
|
report = {
|
||||||
reasonType: state.selectedOption.reason,
|
reasonType,
|
||||||
reason: state.details,
|
reason: state.details,
|
||||||
subject: {
|
subject: {
|
||||||
$type: 'chat.bsky.convo.defs#messageRef',
|
$type: 'chat.bsky.convo.defs#messageRef',
|
||||||
@@ -82,7 +103,7 @@ export function useSubmitReportMutation() {
|
|||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
logger.info('Submitting report', {
|
logger.info('Submitting report', {
|
||||||
labeler: {
|
labeler: {
|
||||||
handle: state.selectedLabeler.creator.handle,
|
handle: labeler.creator.handle,
|
||||||
},
|
},
|
||||||
report,
|
report,
|
||||||
})
|
})
|
||||||
@@ -90,7 +111,7 @@ export function useSubmitReportMutation() {
|
|||||||
await agent.createModerationReport(report, {
|
await agent.createModerationReport(report, {
|
||||||
encoding: 'application/json',
|
encoding: 'application/json',
|
||||||
headers: {
|
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,
|
* Set of report reasons that should only be sent Bluesky's moderation service.
|
||||||
* such as Bluesky.
|
|
||||||
*/
|
*/
|
||||||
export const MOD_AUTHORITY_ONLY_REPORT_REASONS: Set<OzoneReportDefs.ReasonType> =
|
export const BSKY_LABELER_ONLY_REPORT_REASONS: Set<OzoneReportDefs.ReasonType> =
|
||||||
new Set([
|
new Set([
|
||||||
OzoneReportDefs.REASONCHILDSAFETYCSAM,
|
OzoneReportDefs.REASONCHILDSAFETYCSAM,
|
||||||
OzoneReportDefs.REASONCHILDSAFETYGROOM,
|
OzoneReportDefs.REASONCHILDSAFETYGROOM,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {Pressable, View} from 'react-native'
|
import {Pressable, View} from 'react-native'
|
||||||
import {type ScrollView} from 'react-native-gesture-handler'
|
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 {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
@@ -30,7 +30,11 @@ import {createStaticClick, InlineLinkText, Link} from '#/components/Link'
|
|||||||
import {Loader} from '#/components/Loader'
|
import {Loader} from '#/components/Loader'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
import {useSubmitReportMutation} from './action'
|
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 {useCopyForSubject} from './copy'
|
||||||
import {initialState, reducer} from './state'
|
import {initialState, reducer} from './state'
|
||||||
import {type ReportDialogProps, type ReportSubject} from './types'
|
import {type ReportDialogProps, type ReportSubject} from './types'
|
||||||
@@ -135,14 +139,25 @@ function Inner(props: ReportDialogProps) {
|
|||||||
})
|
})
|
||||||
.filter(l => {
|
.filter(l => {
|
||||||
if (!state.selectedOption) return true
|
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
|
const reasonTypes: string[] | undefined = l.reasonTypes
|
||||||
if (reasonTypes === undefined) return true
|
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])
|
}, [props, allLabelers, state.selectedOption])
|
||||||
const hasSupportedLabelers = !!supportedLabelers.length
|
const hasSupportedLabelers = !!supportedLabelers.length
|
||||||
const hasSingleSupportedLabeler = supportedLabelers.length === 1
|
const hasSingleSupportedLabeler = supportedLabelers.length === 1
|
||||||
|
|
||||||
|
console.log(supportedLabelers)
|
||||||
|
|
||||||
const onSubmit = React.useCallback(async () => {
|
const onSubmit = React.useCallback(async () => {
|
||||||
dispatch({type: 'clearError'})
|
dispatch({type: 'clearError'})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user