From 611dd0ea5cb80e8488d0ea17a4d18ebc39edaa25 Mon Sep 17 00:00:00 2001 From: Spence Pope Date: Thu, 15 Oct 2026 16:35:06 -0400 Subject: [PATCH] Report profile links as link records (#11988) --- .../moderation/ReportDialog/action.ts | 22 +- .../moderation/ReportDialog/const.ts | 2 +- .../moderation/ReportDialog/copy.ts | 19 +- .../moderation/ReportDialog/index.tsx | 5 +- .../moderation/ReportDialog/types.ts | 12 +- .../utils/parseReportSubject.test.ts | 23 ++ .../ReportDialog/utils/parseReportSubject.ts | 7 + .../components/LinkFormDialog.tsx | 8 +- .../components/LinkPreviewSheet.tsx | 30 +-- .../profileLinks/components/ProfileLinks.tsx | 26 ++- .../components/ReportLinkDialog.tsx | 214 ++++++++++++++++++ src/features/profileLinks/index.ts | 4 + src/features/profileLinks/providers.ts | 5 + src/view/com/profile/ProfileMenu.tsx | 23 ++ 14 files changed, 332 insertions(+), 68 deletions(-) create mode 100644 src/components/moderation/ReportDialog/utils/parseReportSubject.test.ts create mode 100644 src/features/profileLinks/components/ReportLinkDialog.tsx diff --git a/src/components/moderation/ReportDialog/action.ts b/src/components/moderation/ReportDialog/action.ts index df6fcff04..ebb3cb227 100644 --- a/src/components/moderation/ReportDialog/action.ts +++ b/src/components/moderation/ReportDialog/action.ts @@ -22,7 +22,6 @@ export function useSubmitReportMutation() { subject, state, videoTimestampSeconds, - profileLinkUrl, }: { subject: ParsedReportSubject state: ReportState @@ -31,10 +30,6 @@ export function useSubmitReportMutation() { * post with a video. */ videoTimestampSeconds?: number - /** - * The profile link the report started from, if any. - */ - profileLinkUrl?: string }) { if (!state.selectedOption) { throw new Error(_(msg`Please select a reason for this report`)) @@ -82,7 +77,8 @@ export function useSubmitReportMutation() { case 'post': case 'list': case 'feed': - case 'starterPack': { + case 'starterPack': + case 'profileLink': { report = { reasonType, reason: state.details, @@ -122,25 +118,15 @@ export function useSubmitReportMutation() { } } - const isBskyModService = labeler.creator.did === api.moderation.did const modToolMeta = state.includeVideoTimestamp && videoTimestampSeconds != null && subject.type === 'post' && - isBskyModService + labeler.creator.did === api.moderation.did ? {videoTimestampSeconds} : undefined - if (profileLinkUrl && subject.type === 'account' && isBskyModService) { - /* - * Ozone can filter reports by tool name but not by metadata, so link - * reports get their own name to make them countable. - */ - report.modTool = { - name: `${REPORT_MOD_TOOL_NAME}/profile-link`, - meta: {profileLinkUrl}, - } - } else if (modToolMeta) { + if (modToolMeta) { report.modTool = { name: REPORT_MOD_TOOL_NAME, meta: modToolMeta, diff --git a/src/components/moderation/ReportDialog/const.ts b/src/components/moderation/ReportDialog/const.ts index 34f736a86..159ebecf9 100644 --- a/src/components/moderation/ReportDialog/const.ts +++ b/src/components/moderation/ReportDialog/const.ts @@ -186,4 +186,4 @@ export const BSKY_LABELER_ONLY_REPORT_REASONS: Set = - new Set(['convoMessage', 'convo', 'status']) + new Set(['convoMessage', 'convo', 'status', 'profileLink']) diff --git a/src/components/moderation/ReportDialog/copy.ts b/src/components/moderation/ReportDialog/copy.ts index 50f7ed4bd..f8723eeec 100644 --- a/src/components/moderation/ReportDialog/copy.ts +++ b/src/components/moderation/ReportDialog/copy.ts @@ -3,20 +3,11 @@ import {useLingui} from '@lingui/react/macro' import {type ParsedReportSubject} from './types' -export function useCopyForSubject( - subject: ParsedReportSubject, - {isProfileLink = false}: {isProfileLink?: boolean} = {}, -) { +export function useCopyForSubject(subject: ParsedReportSubject) { const {t: l} = useLingui() return useMemo(() => { switch (subject.type) { case 'account': { - if (isProfileLink) { - return { - title: l`Report this link`, - subtitle: l`Why should this link be reviewed?`, - } - } return { title: l`Report this user`, subtitle: l`Why should this user be reviewed?`, @@ -46,6 +37,12 @@ export function useCopyForSubject( subtitle: l`Why should this feed be reviewed?`, } } + case 'profileLink': { + return { + title: l`Report this link`, + subtitle: l`Why should this link be reviewed?`, + } + } case 'starterPack': { return { title: l`Report this Starter Pack`, @@ -75,5 +72,5 @@ export function useCopyForSubject( } } } - }, [l, subject, isProfileLink]) + }, [l, subject]) } diff --git a/src/components/moderation/ReportDialog/index.tsx b/src/components/moderation/ReportDialog/index.tsx index 662c607a3..ee5ea7038 100644 --- a/src/components/moderation/ReportDialog/index.tsx +++ b/src/components/moderation/ReportDialog/index.tsx @@ -167,9 +167,7 @@ function Inner( refetch: refetchLabelers, } = useMyLabelersQuery({excludeNonConfigurableLabelers: true}) const isLoading = useDelayedLoading(500, isLabelerLoading) - const copy = useCopyForSubject(props.subject, { - isProfileLink: !!props.profileLinkUrl, - }) + const copy = useCopyForSubject(props.subject) const {categories, getCategory} = useReportOptions() const [state, dispatch] = useReducer(reducer, initialState) @@ -271,7 +269,6 @@ function Inner( subject: props.subject, state, videoTimestampSeconds, - profileLinkUrl: props.profileLinkUrl, }), ) setIsSuccess(true) diff --git a/src/components/moderation/ReportDialog/types.ts b/src/components/moderation/ReportDialog/types.ts index 2e14e7292..3134109e5 100644 --- a/src/components/moderation/ReportDialog/types.ts +++ b/src/components/moderation/ReportDialog/types.ts @@ -23,6 +23,7 @@ export type ReportSubject = | $Typed | $Typed | $Typed + | $Typed | ReportSubjectConvoMessage | ReportSubjectConvo @@ -64,6 +65,12 @@ export type ParsedReportSubject = cid: string nsid: string } + | { + type: 'profileLink' + uri: string + cid: string + nsid: string + } | { type: 'account' did: string @@ -87,9 +94,4 @@ export type ReportDialogProps = { * Called after the dialog finishes closing. */ onClose?: () => void - /** - * The profile link this report started from. Tags the report so link - * reports can be counted separately in Ozone. - */ - profileLinkUrl?: string } diff --git a/src/components/moderation/ReportDialog/utils/parseReportSubject.test.ts b/src/components/moderation/ReportDialog/utils/parseReportSubject.test.ts new file mode 100644 index 000000000..46a8af5b8 --- /dev/null +++ b/src/components/moderation/ReportDialog/utils/parseReportSubject.test.ts @@ -0,0 +1,23 @@ +import {describe, expect, it} from '@jest/globals' + +import {type app} from '#/lexicons' +import {parseReportSubject} from './parseReportSubject' + +describe('parseReportSubject', () => { + it('reports a profile link as its link record', () => { + const link = { + $type: 'app.bsky.actor.defs#profileLinkView', + uri: 'at://did:plc:kat/app.bsky.actor.link/3kabc', + cid: 'bafyreigjtngycmin6ae2654mhhjcmtusy34pz6m5nsonc7vvubll6pokiu', + url: 'https://ko-fi.com/kat', + } as app.bsky.actor.defs.ProfileLinkView & { + $type: 'app.bsky.actor.defs#profileLinkView' + } + expect(parseReportSubject(link)).toEqual({ + type: 'profileLink', + uri: link.uri, + cid: link.cid, + nsid: 'app.bsky.actor.link', + }) + }) +}) diff --git a/src/components/moderation/ReportDialog/utils/parseReportSubject.ts b/src/components/moderation/ReportDialog/utils/parseReportSubject.ts index 8b03c7b02..c79f1dd94 100644 --- a/src/components/moderation/ReportDialog/utils/parseReportSubject.ts +++ b/src/components/moderation/ReportDialog/utils/parseReportSubject.ts @@ -63,6 +63,13 @@ export function parseReportSubject( cid: subject.cid, nsid: 'app.bsky.graph.starterPack', } + } else if (bsky.isType(app.bsky.actor.defs.profileLinkView, subject)) { + return { + type: 'profileLink', + uri: subject.uri, + cid: subject.cid, + nsid: 'app.bsky.actor.link', + } } else if (bsky.isType(app.bsky.feed.defs.postView, subject)) { const record = subject.record const embed = bsky.post.parseEmbed(subject.embed) diff --git a/src/features/profileLinks/components/LinkFormDialog.tsx b/src/features/profileLinks/components/LinkFormDialog.tsx index b43e3770a..c7b44f893 100644 --- a/src/features/profileLinks/components/LinkFormDialog.tsx +++ b/src/features/profileLinks/components/LinkFormDialog.tsx @@ -16,6 +16,7 @@ import {useAnalytics} from '#/analytics' import {IS_LIQUID_GLASS} from '#/env' import {useSupportPalette} from '../palette' import { + formatLinkUrl, getLinkHost, normalizeProfileLinkUrl, validateLinkInput, @@ -43,11 +44,6 @@ function suggestTitle(pageTitle: string | undefined): string { return (lastSpace > 0 ? cut.slice(0, lastSpace) : cut).trim() } -/** Shows the saved link the way people type it, without the scheme. */ -function formatUrl(url: string): string { - return url.replace(/^https?:\/\/(www\.)?/i, '').replace(/\/$/, '') -} - /** * Adds, edits or removes a profile link. Pass the link being edited, or null * to add a new one. The caller decides what saving means. @@ -109,7 +105,7 @@ function LinkFormInner({ const supportedSitesControl = Dialog.useDialogControl() const isEditing = !!link - const startingInput = link ? formatUrl(link.url) : '' + const startingInput = link ? formatLinkUrl(link.url) : '' const [input, setInput] = useState(startingInput) const [touched, setTouched] = useState(false) const [title, setTitle] = useState(link?.title ?? '') diff --git a/src/features/profileLinks/components/LinkPreviewSheet.tsx b/src/features/profileLinks/components/LinkPreviewSheet.tsx index d0318271a..d1511c7b1 100644 --- a/src/features/profileLinks/components/LinkPreviewSheet.tsx +++ b/src/features/profileLinks/components/LinkPreviewSheet.tsx @@ -25,8 +25,8 @@ export function LinkPreviewSheet({ control: Dialog.DialogControlProps link: ProfileLink | null onOpen: (link: ProfileLink) => void - /** Runs after the sheet closes. */ - onReport: () => void + /** Runs after the sheet closes. Leave unset to hide reporting. */ + onReport?: () => void }) { return ( @@ -49,7 +49,7 @@ function LinkPreviewSheetInner({ }: { link: ProfileLink onOpen: (link: ProfileLink) => void - onReport: () => void + onReport?: () => void }) { const control = Dialog.useDialogContext() const {t: l} = useLingui() @@ -102,17 +102,19 @@ function LinkPreviewSheetInner({ Copy link - + {onReport ? ( + + ) : null} diff --git a/src/features/profileLinks/components/ProfileLinks.tsx b/src/features/profileLinks/components/ProfileLinks.tsx index 1f05cd5cf..0ea6ed90f 100644 --- a/src/features/profileLinks/components/ProfileLinks.tsx +++ b/src/features/profileLinks/components/ProfileLinks.tsx @@ -257,16 +257,24 @@ function ProfileLinksRow({ control={previewControl} link={activeLink} onOpen={open} - onReport={() => reportControl.open()} - /> - reportControl.open() + : undefined + } /> + {activeLink?.uri && activeLink.cid ? ( + + ) : null} )} diff --git a/src/features/profileLinks/components/ReportLinkDialog.tsx b/src/features/profileLinks/components/ReportLinkDialog.tsx new file mode 100644 index 000000000..7a996f9c4 --- /dev/null +++ b/src/features/profileLinks/components/ReportLinkDialog.tsx @@ -0,0 +1,214 @@ +import {useState} from 'react' +import {View} from 'react-native' +import {Trans, useLingui} from '@lingui/react/macro' + +import {atoms as a, useTheme, web} from '#/alf' +import {Button} from '#/components/Button' +import * as Dialog from '#/components/Dialog' +import {ChevronRight_Stroke2_Corner0_Rounded as ChevronRightIcon} from '#/components/icons/Chevron' +import {Globe_Stroke2_Corner0_Rounded as GlobeIcon} from '#/components/icons/Globe' +import { + ReportDialog, + useReportDialogControl, +} from '#/components/moderation/ReportDialog' +import {Text} from '#/components/Typography' +import {type app} from '#/lexicons' +import {useSupportPalette} from '../palette' +import {formatLinkUrl, getLinkHost, getSupportProvider} from '../providers' +import {useProfileLinksEnabled, useProfileViewLinks} from '../state' +import {type ProfileLink} from '../types' +import {LinkFavicon, linkFaviconUrl} from './LinkFavicon' +import {ProviderLogo} from './ProviderLogo' + +const ICON_SIZE = 32 + +/** + * The links on someone else's profile that can be reported: those shown to + * this viewer and backed by a link record. + */ +export function useReportableProfileLinks( + profile: app.bsky.actor.defs.ProfileViewDetailed, +): ProfileLink[] { + const enabled = useProfileLinksEnabled() + const links = useProfileViewLinks(profile) + if (!enabled) return [] + return links.filter(link => link.uri && link.cid) +} + +/** + * "Report a link" from the profile menu: pick one of the profile's links, then + * report its link record. Works where long-pressing a link isn't available, + * like on web. + */ +export function ReportLinkDialog({ + control, + links, +}: { + control: Dialog.DialogControlProps + links: ProfileLink[] +}) { + const reportControl = useReportDialogControl() + const [selected, setSelected] = useState(null) + const reported = selected ?? links[0] + + return ( + <> + + + { + control.close(() => { + setSelected(link) + reportControl.open() + }) + }} + /> + + {reported?.uri && reported.cid ? ( + + ) : null} + + ) +} + +function ReportLinkPicker({ + links, + onSelect, +}: { + links: ProfileLink[] + onSelect: (link: ProfileLink) => void +}) { + const {t: l} = useLingui() + const t = useTheme() + + return ( + + + + Report a link + + + Which link do you want to report? + + + + {links.map(link => { + const label = linkRowLabel(link) + return ( + + ) + })} + + + + ) +} + +/** The owner's title, the support platform's name, or the bare domain. */ +function linkRowLabel(link: ProfileLink): string { + return ( + link.title || getSupportProvider(link.url)?.name || getLinkHost(link.url) + ) +} + +function LinkRowIcon({link}: {link: ProfileLink}) { + const t = useTheme() + const palette = useSupportPalette() + const provider = getSupportProvider(link.url) + const globe = + + if (provider) { + return ( + + + + ) + } + const faviconUrl = linkFaviconUrl(link, undefined) + return ( + + {faviconUrl ? ( + + ) : ( + globe + )} + + ) +} diff --git a/src/features/profileLinks/index.ts b/src/features/profileLinks/index.ts index 9f40d00ab..a7159c35f 100644 --- a/src/features/profileLinks/index.ts +++ b/src/features/profileLinks/index.ts @@ -1,5 +1,9 @@ export {ProfileHeaderLinks} from './components/ProfileLinks' export {ProfileLinksEditor} from './components/ProfileLinksEditor' +export { + ReportLinkDialog, + useReportableProfileLinks, +} from './components/ReportLinkDialog' export {logProfileLinkChanges} from './metrics' export {sameProfileLinks} from './record' export { diff --git a/src/features/profileLinks/providers.ts b/src/features/profileLinks/providers.ts index 8e197e545..c3f7272bf 100644 --- a/src/features/profileLinks/providers.ts +++ b/src/features/profileLinks/providers.ts @@ -225,6 +225,11 @@ export function isShortenerLink(url: string): boolean { return SHORTENER_DOMAINS.some(domain => hostMatchesDomain(host, domain)) } +/** A link the way people type it, without the scheme. */ +export function formatLinkUrl(url: string): string { + return url.replace(/^https?:\/\/(www\.)?/i, '').replace(/\/$/, '') +} + export function getLinkHost(url: string): string { try { return new URL(url).hostname.replace(/^www\./, '') diff --git a/src/view/com/profile/ProfileMenu.tsx b/src/view/com/profile/ProfileMenu.tsx index 35dfaa8b3..cc46f7a64 100644 --- a/src/view/com/profile/ProfileMenu.tsx +++ b/src/view/com/profile/ProfileMenu.tsx @@ -61,6 +61,10 @@ import {useActorStatus, useLiveNowConfig} from '#/features/liveNow' import {EditLiveDialog} from '#/features/liveNow/components/EditLiveDialog' import {GoLiveDialog} from '#/features/liveNow/components/GoLiveDialog' import {GoLiveDisabledDialog} from '#/features/liveNow/components/GoLiveDisabledDialog' +import { + ReportLinkDialog, + useReportableProfileLinks, +} from '#/features/profileLinks' import {type app} from '#/lexicons' import {useDevMode} from '#/storage/hooks/dev-mode' @@ -100,6 +104,8 @@ let ProfileMenu = ({ const goLiveDisabledDialogControl = useDialogControl() const addToStarterPacksDialogControl = useDialogControl() const addToListsDialogControl = useDialogControl() + const reportLinkDialogControl = useDialogControl() + const reportableLinks = useReportableProfileLinks(profile) const showLoggedOutWarning = useMemo(() => { return ( @@ -520,6 +526,17 @@ let ProfileMenu = ({ + {reportableLinks.length > 0 && ( + reportLinkDialogControl.open()}> + + Report a link + + + + )} )} @@ -569,6 +586,12 @@ let ProfileMenu = ({ $type: 'app.bsky.actor.defs#profileViewDetailed', }} /> + {reportableLinks.length > 0 && ( + + )}