Little cleanup
This commit is contained in:
@@ -31,14 +31,15 @@ import * as Toast from '#/view/com/util/Toast'
|
|||||||
import {usePreferencesQuery} from '#/state/queries/preferences'
|
import {usePreferencesQuery} from '#/state/queries/preferences'
|
||||||
import {useModServicesDetailedInfoQuery} from '#/state/queries/modservice'
|
import {useModServicesDetailedInfoQuery} from '#/state/queries/modservice'
|
||||||
import {
|
import {
|
||||||
getLabelGroupsFromLabels,
|
|
||||||
getModerationServiceTitle,
|
getModerationServiceTitle,
|
||||||
useConfigurableContentLabelGroups,
|
useConfigurableContentLabelGroups,
|
||||||
useConfigurableProfileLabelGroups,
|
useConfigurableProfileLabelGroups,
|
||||||
|
getLabelGroupToLabelerMap,
|
||||||
} from '#/lib/moderation'
|
} from '#/lib/moderation'
|
||||||
import {DMCA_LINK} from '#/components/dialogs/ReportDialog/const'
|
import {DMCA_LINK} from '#/components/dialogs/ReportDialog/const'
|
||||||
import {Link} from '#/components/Link'
|
import {Link} from '#/components/Link'
|
||||||
import {SquareArrowTopRight_Stroke2_Corner0_Rounded as SquareArrowTopRight} from '#/components/icons/SquareArrowTopRight'
|
import {SquareArrowTopRight_Stroke2_Corner0_Rounded as SquareArrowTopRight} from '#/components/icons/SquareArrowTopRight'
|
||||||
|
// import {getAgent} from '#/state/session'
|
||||||
|
|
||||||
export type ReportDialogLabelIds = LabelGroupDefinition['id'] | 'other'
|
export type ReportDialogLabelIds = LabelGroupDefinition['id'] | 'other'
|
||||||
export type ReportDialogProps =
|
export type ReportDialogProps =
|
||||||
@@ -161,7 +162,7 @@ function SubmitViewLoader({
|
|||||||
}: {
|
}: {
|
||||||
children: (props: {
|
children: (props: {
|
||||||
labelers: AppBskyModerationDefs.ModServiceViewDetailed[]
|
labelers: AppBskyModerationDefs.ModServiceViewDetailed[]
|
||||||
labelGroupToModServiceMap: Record<LabelGroupDefinition['id'], string[]>
|
labelGroupToModServiceMap: ReturnType<typeof getLabelGroupToLabelerMap>
|
||||||
}) => React.ReactNode
|
}) => React.ReactNode
|
||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
@@ -178,28 +179,7 @@ function SubmitViewLoader({
|
|||||||
})
|
})
|
||||||
const labelGroupToModServiceMap = React.useMemo(() => {
|
const labelGroupToModServiceMap = React.useMemo(() => {
|
||||||
if (!modservices) return {}
|
if (!modservices) return {}
|
||||||
|
return getLabelGroupToLabelerMap(modservices)
|
||||||
const groups: Partial<
|
|
||||||
Record<
|
|
||||||
ReportDialogLabelIds,
|
|
||||||
AppBskyModerationDefs.ModServiceViewDetailed[]
|
|
||||||
>
|
|
||||||
> = {
|
|
||||||
// report `other` to all labelers
|
|
||||||
other: modservices,
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const modservice of modservices) {
|
|
||||||
const labelGroups = getLabelGroupsFromLabels(
|
|
||||||
modservice.policies.labelValues,
|
|
||||||
)
|
|
||||||
for (const group of labelGroups) {
|
|
||||||
const g = (groups[group.id] = groups[group.id] || [])
|
|
||||||
g.push(modservice)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return groups
|
|
||||||
}, [modservices])
|
}, [modservices])
|
||||||
|
|
||||||
const isLoading = isPreferencesLoading || isModServicesLoading
|
const isLoading = isPreferencesLoading || isModServicesLoading
|
||||||
@@ -212,27 +192,24 @@ function SubmitViewLoader({
|
|||||||
) : error || !(preferences && modservices) ? null : ( // TODO
|
) : error || !(preferences && modservices) ? null : ( // TODO
|
||||||
children({
|
children({
|
||||||
labelers: modservices,
|
labelers: modservices,
|
||||||
// TODO mismatched types
|
|
||||||
// @ts-ignore
|
|
||||||
labelGroupToModServiceMap,
|
labelGroupToModServiceMap,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function SubmitView({
|
function SubmitView({
|
||||||
|
params,
|
||||||
selectedLabelGroup,
|
selectedLabelGroup,
|
||||||
goBack,
|
goBack,
|
||||||
onSubmitComplete,
|
onSubmitComplete,
|
||||||
labelGroupToModServiceMap,
|
labelGroupToModServiceMap,
|
||||||
}: {
|
}: {
|
||||||
|
params: ReportDialogProps
|
||||||
selectedLabelGroup: ReportDialogLabelIds
|
selectedLabelGroup: ReportDialogLabelIds
|
||||||
goBack: () => void
|
goBack: () => void
|
||||||
onSubmitComplete: () => void
|
onSubmitComplete: () => void
|
||||||
labelers: AppBskyModerationDefs.ModServiceViewDetailed[]
|
labelers: AppBskyModerationDefs.ModServiceViewDetailed[]
|
||||||
labelGroupToModServiceMap: Record<
|
labelGroupToModServiceMap: ReturnType<typeof getLabelGroupToLabelerMap>
|
||||||
ReportDialogLabelIds,
|
|
||||||
AppBskyModerationDefs.ModServiceViewDetailed[]
|
|
||||||
>
|
|
||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
@@ -246,12 +223,28 @@ function SubmitView({
|
|||||||
const submit = React.useCallback(async () => {
|
const submit = React.useCallback(async () => {
|
||||||
setSubmitting(true)
|
setSubmitting(true)
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||||
|
|
||||||
|
const $type =
|
||||||
|
params.type === 'content'
|
||||||
|
? 'com.atproto.repo.strongRef'
|
||||||
|
: 'com.atproto.admin.defs#repoRef'
|
||||||
|
const report = {
|
||||||
|
reasonType: selectedLabelGroup, // TODO map to reasons
|
||||||
|
subject: {
|
||||||
|
$type,
|
||||||
|
...params,
|
||||||
|
},
|
||||||
|
reason: details,
|
||||||
|
}
|
||||||
|
console.log(report)
|
||||||
|
// await getAgent().createModerationReport(report)
|
||||||
|
|
||||||
setSubmitting(false)
|
setSubmitting(false)
|
||||||
|
|
||||||
Toast.show(`Thank you. Your report has been sent.`)
|
Toast.show(`Thank you. Your report has been sent.`)
|
||||||
|
|
||||||
onSubmitComplete()
|
onSubmitComplete()
|
||||||
}, [onSubmitComplete])
|
}, [params, details, selectedLabelGroup, onSubmitComplete])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[a.gap_2xl]}>
|
<View style={[a.gap_2xl]}>
|
||||||
@@ -431,10 +424,9 @@ export function ReportDialog({
|
|||||||
{selectedLabelGroup ? (
|
{selectedLabelGroup ? (
|
||||||
<SubmitViewLoader>
|
<SubmitViewLoader>
|
||||||
{props => (
|
{props => (
|
||||||
// TODO same types mismatch
|
|
||||||
// @ts-ignore
|
|
||||||
<SubmitView
|
<SubmitView
|
||||||
{...props}
|
{...props}
|
||||||
|
params={params}
|
||||||
selectedLabelGroup={selectedLabelGroup}
|
selectedLabelGroup={selectedLabelGroup}
|
||||||
goBack={() => setSelectedLabelGroup(undefined)}
|
goBack={() => setSelectedLabelGroup(undefined)}
|
||||||
onSubmitComplete={control.close}
|
onSubmitComplete={control.close}
|
||||||
|
|||||||
+35
-1
@@ -1,5 +1,11 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {ModerationCause, LABEL_GROUPS, LabelGroupDefinition} from '@atproto/api'
|
import {
|
||||||
|
ModerationCause,
|
||||||
|
LABEL_GROUPS,
|
||||||
|
LabelGroupDefinition,
|
||||||
|
AppBskyModerationDefs,
|
||||||
|
} from '@atproto/api'
|
||||||
|
|
||||||
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
||||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||||
|
|
||||||
@@ -77,3 +83,31 @@ export function getModerationServiceTitle({
|
|||||||
? sanitizeDisplayName(displayName)
|
? sanitizeDisplayName(displayName)
|
||||||
: sanitizeHandle(handle, '@')
|
: sanitizeHandle(handle, '@')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getLabelGroupToLabelerMap(
|
||||||
|
labelers: AppBskyModerationDefs.ModServiceViewDetailed[],
|
||||||
|
) {
|
||||||
|
if (!labelers) return {}
|
||||||
|
|
||||||
|
const groups: Partial<
|
||||||
|
Record<
|
||||||
|
LabelGroupDefinition['id'] | 'other',
|
||||||
|
AppBskyModerationDefs.ModServiceViewDetailed[]
|
||||||
|
>
|
||||||
|
> = {
|
||||||
|
// `other` reports go to all labelers TODO confirm this
|
||||||
|
other: labelers,
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const modservice of labelers) {
|
||||||
|
const labelGroups = getLabelGroupsFromLabels(
|
||||||
|
modservice.policies.labelValues,
|
||||||
|
)
|
||||||
|
for (const group of labelGroups) {
|
||||||
|
const g = (groups[group.id] = groups[group.id] || [])
|
||||||
|
g.push(modservice)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return groups
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user