Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174import {type StyleProp, View, type ViewStyle} from 'react-native'import {type ModerationCause, type ModerationUI} from '@bsky/sdk/moderation'import {plural} from '@lingui/core/macro'import {useLingui} from '@lingui/react/macro'
import { filterUserFacingLabels, getModerationCauseKey, unique,} from '#/lib/moderation'import {useSession} from '#/state/session'import {atoms as a} from '#/alf'import { LabelsOnMeDialog, useLabelsOnMeDialogControl,} from '#/components/moderation/LabelsOnMeDialog'import * as Pills from '#/components/Pills'import {type app, type com} from '#/lexicons'
export function PostAlerts({ post, modui, view = 'compact', style, additionalCauses,}: { post?: app.bsky.feed.defs.PostView modui: ModerationUI /** * Expanded views (e.g. the thread anchor post) render larger pills and * surface the "+n" additional labels pill. Compact views (feeds, replies) * keep the alerts minimal. */ view?: 'expanded' | 'compact' includeMute?: boolean style?: StyleProp<ViewStyle> additionalCauses?: ModerationCause[] | Pills.AppModerationCause[]}) { const {currentAccount} = useSession() const size: Pills.CommonProps['size'] = view === 'expanded' ? 'lg' : 'sm'
const alerts = modui.alerts.filter(unique) const informs = modui.informs.filter(unique) /* * The "+n" pill surfaces labels for the author to review and appeal, so it * only applies when the viewer is the author, and only in expanded views. * It renders even when no other moderation is visible, since it may be the * author's only entry point to appeal labels on their content. */ const isOwnPost = !!post && post.author.did === currentAccount?.did const allLabels: com.atproto.label.defs.Label[] = isOwnPost && view === 'expanded' ? [ ...(post.labels ?? []), /* * Account labels appear on Profile. We don't show them here unless the * user's mod settings are configured such that the labels land in the * modui handling. */ // ...(post.author.labels ?? []) ] : [] /* * Labels that the moderation system already surfaces in this context - * whether as an alert, an inform, or a blur handled by ContentHider - should * not be repeated in the "+n" pill. */ const shownCauses = [...alerts, ...informs, ...modui.blurs] const additionalLabels = filterUserFacingLabels( allLabels, currentAccount?.did, ).filter(label => shownCauses.every( cause => cause.type !== 'label' || cause.label.val !== label.val || cause.label.src !== label.src || cause.label.uri !== label.uri, ), )
if ( !modui.alert && !modui.inform && !additionalCauses?.length && !additionalLabels.length ) { return null }
return ( <Pills.Row size={size} style={[size === 'sm' && {marginLeft: -3}, style]}> {alerts.map(cause => ( <Pills.Label key={getModerationCauseKey(cause)} cause={cause} size={size} noBg={size === 'sm'} /> ))} {informs.map(cause => ( <Pills.Label key={getModerationCauseKey(cause)} cause={cause} size={size} noBg={size === 'sm'} /> ))} {additionalCauses?.map(cause => ( <Pills.Label key={getModerationCauseKey(cause)} cause={cause} size={size} noBg={size === 'sm'} /> ))} {additionalLabels.length ? ( <AdditionalLabels labels={additionalLabels} size={size} hasPrecedingPills={ alerts.length > 0 || informs.length > 0 || (additionalCauses?.length ?? 0) > 0 } /> ) : null} </Pills.Row> )}
function AdditionalLabels({ labels, size, hasPrecedingPills,}: { labels: com.atproto.label.defs.Label[] size?: Pills.CommonProps['size'] /** * The compact "+n" syntax only makes sense as a continuation of other * pills. When this pill stands alone, spell it out. */ hasPrecedingPills: boolean}) { const {t: l} = useLingui() const control = useLabelsOnMeDialogControl()
return ( <View style={[a.flex_row]}> <LabelsOnMeDialog control={control} labels={labels} type="content" />
<Pills.LabelBase label={l`${plural(labels.length, { one: '# label applied to your post', other: '# labels applied to your post', })}`} cta={ hasPrecedingPills ? l`+${labels.length}` : l`${plural(labels.length, { one: '# label applied', other: '# labels applied', })}` } size={size} noBg={size === 'sm'} onPress={() => { control.open() }} /> </View> )}