Merge branch '3p-moderators' of github.com:bluesky-social/social-app into 3p-moderators

This commit is contained in:
Paul Frazee
2024-02-15 11:13:27 -08:00
10 changed files with 204 additions and 73 deletions
+62 -1
View File
@@ -1,5 +1,11 @@
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 {sanitizeHandle} from '#/lib/strings/handles'
@@ -39,6 +45,33 @@ export function useConfigurableLabelGroups() {
return React.useMemo(() => getConfigurableLabelGroups(), [])
}
export function useConfigurableContentLabelGroups() {
return React.useMemo(() => {
const groups = getConfigurableLabelGroups()
return groups.filter(group => {
return group.labels.every(l => l.targets.includes('content'))
})
}, [])
}
export function useConfigurableProfileLabelGroups() {
return React.useMemo(() => {
const groups = getConfigurableLabelGroups()
return groups.filter(group => {
return group.labels.every(l => l.targets.includes('profile'))
})
}, [])
}
export function useConfigurableAccountLabelGroups() {
return React.useMemo(() => {
const groups = getConfigurableLabelGroups()
return groups.filter(group => {
return group.labels.every(l => l.targets.includes('account'))
})
}, [])
}
export function getModerationServiceTitle({
displayName,
handle,
@@ -50,3 +83,31 @@ export function getModerationServiceTitle({
? sanitizeDisplayName(displayName)
: 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
}
+5 -1
View File
@@ -4,7 +4,7 @@ import {useLingui} from '@lingui/react'
import {useMemo} from 'react'
export type LabelGroupStrings = Record<
keyof typeof LABEL_GROUPS,
keyof typeof LABEL_GROUPS | 'other',
{name: string; description: string}
>
@@ -116,6 +116,10 @@ export function useLabelGroupStrings(): LabelGroupStrings {
msg`Helpful annotations to explain intent, such as satire or parody.`,
),
},
other: {
name: _(msg`Other`),
description: _(msg`Other content not covered by the other categories.`),
},
}),
[_],
)