Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125import {AtUri, isAtUriString} from '@atproto/syntax'import {plural} from '@lingui/core/macro'import {useLingui} from '@lingui/react/macro'
import {useGlobalLabelStrings} from '#/lib/moderation/useGlobalLabelStrings'import {getLabelStrings} from '#/lib/moderation/useLabelInfo'import {useLabelDefinitions} from '#/state/preferences'import {type tools} from '#/lexicons'
export type ActionedSubject = tools.ozone.inbox.listActionedSubjects.$OutputBody['subjects'][number]
export function useActionedSubjectLabels( item: Pick< ActionedSubject, 'src' | 'subject' | 'enforcement' | 'latestAction' >,) { const {i18n, t: l} = useLingui() const {labelDefs} = useLabelDefinitions() const globalLabelStrings = useGlobalLabelStrings() const action = item.latestAction
if (!action) return
const isAccount = 'did' in item.subject const isPost = 'uri' in item.subject && isAtUriString(item.subject.uri, {strict: false}) && new AtUri(item.subject.uri).collection === 'app.bsky.feed.post' const policyLabel = action.policies?.[0]?.displayName const label = action.labels?.[0] const labelDefinition = label ? labelDefs[item.src]?.find( definition => definition.identifier === label && definition.definedBy === item.src, ) : undefined const labelName = label ? labelDefinition ? getLabelStrings(i18n.locale, globalLabelStrings, labelDefinition).name : (globalLabelStrings[label]?.name ?? label) : undefined
let subject: string let summary: string | undefined switch (action.type) { case 'contentRemoved': subject = isPost ? l`Your post was removed` : l`Your content was removed` summary = policyLabel ? l`Violates Community Guideline: ${policyLabel}` : undefined break case 'contentRestored': subject = isPost ? l`Your post was restored` : l`Your content was restored` break case 'accountRestored': subject = l`Your account was restored` break case 'communicationSent': subject = l`An email was sent about your account` summary = policyLabel break case 'labelApplied': subject = isAccount ? l`A label was added to your account` : isPost ? l`A label was added to your post` : l`A label was added to your content` summary = labelName ? l`Label: ${labelName}` : undefined break case 'accountSuspended': { subject = l`Your account was suspended` const expiresAt = action.expiresAt if (policyLabel && expiresAt) { const hours = Math.max( 0, Math.round( (Date.parse(expiresAt) - Date.parse(action.createdAt)) / 3_600_000, ), ) const duration = plural(hours, { one: '# hour', other: '# hours', }) summary = // oxlint-disable-next-line react/react-compiler Date.parse(expiresAt) <= Date.now() ? l`${policyLabel} – ${duration}, now expired` : l`${policyLabel} – ${duration}` } else { summary = policyLabel } break } case 'accountTakedown': subject = l`Your account was suspended` summary = policyLabel break case 'reportingRestricted': subject = l`Your ability to submit reports was restricted` summary = policyLabel break case 'credentialsRevoked': subject = l`Your account credentials were revoked` summary = policyLabel break case 'labelRemoved': subject = isAccount ? l`A label was removed from your account` : isPost ? l`A label was removed from your post` : l`A label was removed from your content` summary = labelName ? l`Label: ${labelName}` : undefined break default: subject = l`Moderation notice` break }
return {subject, summary}}