Skip to content

Commit 76f493c

Browse files
Ensure profile labels can be appealed separately from account labels (#5154)
1 parent 4d97a2a commit 76f493c

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

src/components/moderation/LabelsOnMe.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@ import {
1414
} from '#/components/moderation/LabelsOnMeDialog'
1515

1616
export function LabelsOnMe({
17-
details,
17+
type,
1818
labels,
1919
size,
2020
style,
2121
}: {
22-
details: {did: string} | {uri: string; cid: string}
22+
type: 'account' | 'content'
2323
labels: ComAtprotoLabelDefs.Label[] | undefined
2424
size?: ButtonSize
2525
style?: StyleProp<ViewStyle>
2626
}) {
2727
const {_} = useLingui()
2828
const {currentAccount} = useSession()
29-
const isAccount = 'did' in details
3029
const control = useLabelsOnMeDialogControl()
3130

3231
if (!labels || !currentAccount) {
@@ -39,7 +38,7 @@ export function LabelsOnMe({
3938

4039
return (
4140
<View style={[a.flex_row, style]}>
42-
<LabelsOnMeDialog control={control} subject={details} labels={labels} />
41+
<LabelsOnMeDialog control={control} labels={labels} type={type} />
4342

4443
<Button
4544
variant="solid"
@@ -51,7 +50,7 @@ export function LabelsOnMe({
5150
}}>
5251
<ButtonIcon position="left" icon={CircleInfo} />
5352
<ButtonText style={[a.leading_snug]}>
54-
{isAccount ? (
53+
{type === 'account' ? (
5554
<Plural
5655
value={labels.length}
5756
one="# label has been placed on this account"
@@ -82,6 +81,6 @@ export function LabelsOnMyPost({
8281
return null
8382
}
8483
return (
85-
<LabelsOnMe details={post} labels={post.labels} size="tiny" style={style} />
84+
<LabelsOnMe type="content" labels={post.labels} size="tiny" style={style} />
8685
)
8786
}

src/components/moderation/LabelsOnMeDialog.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {msg, Trans} from '@lingui/macro'
55
import {useLingui} from '@lingui/react'
66
import {useMutation} from '@tanstack/react-query'
77

8+
import {useLabelSubject} from '#/lib/moderation'
89
import {useLabelInfo} from '#/lib/moderation/useLabelInfo'
910
import {makeProfileLink} from '#/lib/routes/links'
1011
import {sanitizeHandle} from '#/lib/strings/handles'
@@ -18,21 +19,13 @@ import {InlineLinkText} from '#/components/Link'
1819
import {Text} from '#/components/Typography'
1920
import {Divider} from '../Divider'
2021
import {Loader} from '../Loader'
21-
export {useDialogControl as useLabelsOnMeDialogControl} from '#/components/Dialog'
2222

23-
type Subject =
24-
| {
25-
uri: string
26-
cid: string
27-
}
28-
| {
29-
did: string
30-
}
23+
export {useDialogControl as useLabelsOnMeDialogControl} from '#/components/Dialog'
3124

3225
export interface LabelsOnMeDialogProps {
3326
control: Dialog.DialogOuterProps['control']
34-
subject: Subject
3527
labels: ComAtprotoLabelDefs.Label[]
28+
type: 'account' | 'content'
3629
}
3730

3831
export function LabelsOnMeDialog(props: LabelsOnMeDialogProps) {
@@ -51,8 +44,8 @@ function LabelsOnMeDialogInner(props: LabelsOnMeDialogProps) {
5144
const [appealingLabel, setAppealingLabel] = React.useState<
5245
ComAtprotoLabelDefs.Label | undefined
5346
>(undefined)
54-
const {subject, labels} = props
55-
const isAccount = 'did' in subject
47+
const {labels} = props
48+
const isAccount = props.type === 'account'
5649
const containsSelfLabel = React.useMemo(
5750
() => labels.some(l => l.src === currentAccount?.did),
5851
[currentAccount?.did, labels],
@@ -68,7 +61,6 @@ function LabelsOnMeDialogInner(props: LabelsOnMeDialogProps) {
6861
{appealingLabel ? (
6962
<AppealForm
7063
label={appealingLabel}
71-
subject={subject}
7264
control={props.control}
7365
onPressBack={() => setAppealingLabel(undefined)}
7466
/>
@@ -188,19 +180,18 @@ function Label({
188180

189181
function AppealForm({
190182
label,
191-
subject,
192183
control,
193184
onPressBack,
194185
}: {
195186
label: ComAtprotoLabelDefs.Label
196-
subject: Subject
197187
control: Dialog.DialogOuterProps['control']
198188
onPressBack: () => void
199189
}) {
200190
const {_} = useLingui()
201191
const {labeler, strings} = useLabelInfo(label)
202192
const {gtMobile} = useBreakpoints()
203193
const [details, setDetails] = React.useState('')
194+
const {subject} = useLabelSubject({label})
204195
const isAccountReport = 'did' in subject
205196
const agent = useAgent()
206197
const sourceName = labeler

src/lib/moderation.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import React from 'react'
12
import {
23
AppBskyLabelerDefs,
34
BskyAgent,
5+
ComAtprotoLabelDefs,
46
InterpretedLabelValueDefinition,
57
LABELS,
68
ModerationCause,
@@ -82,3 +84,34 @@ export function isLabelerSubscribed(
8284
}
8385
return modOpts.prefs.labelers.find(l => l.did === labeler)
8486
}
87+
88+
export type Subject =
89+
| {
90+
uri: string
91+
cid: string
92+
}
93+
| {
94+
did: string
95+
}
96+
97+
export function useLabelSubject({label}: {label: ComAtprotoLabelDefs.Label}): {
98+
subject: Subject
99+
} {
100+
return React.useMemo(() => {
101+
const {cid, uri} = label
102+
if (cid) {
103+
return {
104+
subject: {
105+
uri,
106+
cid,
107+
},
108+
}
109+
} else {
110+
return {
111+
subject: {
112+
did: uri,
113+
},
114+
}
115+
}
116+
}, [label])
117+
}

src/screens/Profile/Header/Shell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ let ProfileHeaderShell = ({
8686
style={[a.px_lg, a.py_xs]}
8787
pointerEvents={isIOS ? 'auto' : 'box-none'}>
8888
{isMe ? (
89-
<LabelsOnMe details={{did: profile.did}} labels={profile.labels} />
89+
<LabelsOnMe type="account" labels={profile.labels} />
9090
) : (
9191
<ProfileHeaderAlerts moderation={moderation} />
9292
)}

0 commit comments

Comments
 (0)