feat(trust): network alerts for reported accounts you follow

Fifth slice of TRUST_SCORE.md. useNetworkAlerts reads the viewer's NIP-85
assertions for the accounts they follow and surfaces those trusted people
reported or muted. New /alerts page lists them with Ignore / Unfollow /
Mute / Report (reusing useFollowActions, useMuteUser, ReportDialog) —
inform, never auto-act. Settings -> Trust links to it with a live count;
ignored accounts are device-local. /alerts added to the smoke list.
This commit is contained in:
SkateSpots 2026-10-09 18:32:47 +07:00
parent e66888128f
commit 18a9e28f0b
9 changed files with 269 additions and 2 deletions

View file

@ -2568,7 +2568,10 @@ shared, so `TrustBadge` no longer fires a per-card `useTrustScore` graph query.
**Mute landed:** `useMuteList` + `useMuteUser` (NIP-51 kind-10000, optimistic via
`lib/localMutes.ts`) feed `useAdminModeration`'s new `mutedPubkeys`, so the
shared `filterAdminHidden` drops muted authors across every list; the flagged
notice has a Mute action. Still open: counterparty alerts and the
notice has a Mute action. **Alerts landed:** `useNetworkAlerts` + `/alerts`
(`pages/NetworkAlertsPage.tsx`) list accounts you follow that trusted people
reported/muted, with Ignore/Unfollow/Mute/Report; Settings → Trust links to it
with a count (ignored set in `skatespots:trust:alerts-ignored`). Still open: the
confidence-gated scoring model. Check
`TRUST_SCORE.md` before touching `useTrustScore` / `useRelatrScore` /
`trustFilter`.

View file

@ -72,7 +72,19 @@ flagged notice's reporter breakdown, and Settings → Trust.
content" layer; `includeHidden` admin tooling still bypasses it).
- The flagged notice gains a **Mute** action (Report + Mute + Dismiss).
Still open: counterparty alerts and the confidence-gated scoring model.
## Fifth pass — network alerts (landed)
- **`useNetworkAlerts`** takes the viewer's follows, reads their NIP-85
assertions (batched), and surfaces the accounts that trusted people have
reported or muted (`reporters`/`muters` at/above the flagged threshold).
Ignored accounts are remembered device-locally
(`skatespots:trust:alerts-ignored`).
- **`/alerts`** (`pages/NetworkAlertsPage.tsx`) lists them with
**Ignore / Unfollow / Mute / Report** actions (reusing `useFollowActions`,
`useMuteUser`, `ReportDialog`) — inform, never auto-act.
- Settings → Trust links to it with a live count.
Still open: the confidence-gated scoring model.

View file

@ -145,6 +145,7 @@ const ROUTES = [
'/collections',
'/stats',
'/trust',
'/alerts',
'/mints',
'/app-shop',
'/diy',

View file

@ -68,6 +68,7 @@ const NIP19Page = lazyWithRetry(() => import("./pages/NIP19Page").then(m => ({ d
const LicensePage = lazyWithRetry(() => import("./pages/LicensePage"));
const PrivacyPage = lazyWithRetry(() => import("./pages/PrivacyPage"));
const TrustPage = lazyWithRetry(() => import("./pages/TrustPage"));
const NetworkAlertsPage = lazyWithRetry(() => import("./pages/NetworkAlertsPage"));
const SupportersPage = lazyWithRetry(() => import("./pages/SupportersPage"));
const DonatePage = lazyWithRetry(() => import("./pages/DonatePage"));
const RiderCardPage = lazyWithRetry(() => import("./pages/RiderCardPage"));
@ -142,6 +143,7 @@ export function AppRouter() {
<Route path="/stats" element={<CommunityStatsPage />} />
<Route path="/about" element={<AboutPage />} />
<Route path="/trust" element={<TrustPage />} />
<Route path="/alerts" element={<NetworkAlertsPage />} />
<Route path="/faq" element={<FAQPage />} />
<Route path="/food" element={<FoodPage />} />
<Route path="/wallet" element={<WalletPage />} />

View file

@ -9,6 +9,7 @@ import { useTranslation } from '@/contexts/language';
import { useCurrentUser } from '@/hooks/useCurrentUser';
import { useTrustDisplay } from '@/hooks/useTrustDisplay';
import { useTrustProvider } from '@/hooks/useTrustProvider';
import { useNetworkAlerts } from '@/hooks/useNetworkAlerts';
import {
normalizeProviderPubkey,
normalizeProviderRelay,
@ -27,6 +28,7 @@ export function TrustSettingsCard() {
const { user } = useCurrentUser();
const { enabled, setEnabled } = useTrustDisplay();
const { data: provider } = useTrustProvider();
const { alertCount } = useNetworkAlerts();
const setProvider = useSetTrustProvider();
const [formOpen, setFormOpen] = useState(false);
@ -153,6 +155,18 @@ export function TrustSettingsCard() {
{t('walletUi.trust.howItWorks')}
</Link>
</div>
<div className="rounded-2xl border border-white/10 bg-white/3 p-4">
<Link to="/alerts" className="flex items-center justify-between gap-3">
<span className="text-sm font-bold text-white">{t('trustUi.alertsTitle')}</span>
{user && alertCount > 0 && (
<span className="rounded-full bg-red-500/15 px-2 py-0.5 text-[10px] font-bold text-red-300">
{alertCount}
</span>
)}
</Link>
<p className="mt-1 text-xs text-muted-foreground">{t('trustUi.alertsDesc')}</p>
</div>
</div>
);
}

View file

@ -0,0 +1,63 @@
import { useMemo } from 'react';
import { useFollowing } from './useFollowing';
import { useTrustAssertions } from './useTrustAssertions';
import { useLocalStorage } from './useLocalStorage';
import { FLAGGED_REPORTERS_THRESHOLD } from '@/lib/trustLadder';
/** A muted-by-trusted-people count at/above this also raises an alert. */
const MUTERS_THRESHOLD = FLAGGED_REPORTERS_THRESHOLD;
export interface NetworkAlert {
pubkey: string;
reporters: number;
muters: number;
followers?: number;
hops?: number;
}
/**
* Accounts the viewer follows that trusted people have reported or muted,
* according to the active NIP-85 provider.
*
* This is a safety notice, not an automatic action: the page offers
* ignore / unfollow / mute / report, and the user decides. Dismissed accounts
* are remembered device-locally.
*/
export function useNetworkAlerts() {
const { data: following } = useFollowing();
const { data: assertions, isLoading } = useTrustAssertions(following ?? []);
const [ignored, setIgnored] = useLocalStorage<string[]>('skatespots:trust:alerts-ignored', []);
const alerts = useMemo(() => {
const out: NetworkAlert[] = [];
for (const pubkey of following ?? []) {
if (ignored.includes(pubkey)) continue;
const assertion = assertions?.get(pubkey);
if (!assertion) continue;
const reporters = assertion.reporters ?? 0;
const muters = assertion.muters ?? 0;
if (reporters >= FLAGGED_REPORTERS_THRESHOLD || muters >= MUTERS_THRESHOLD) {
out.push({
pubkey,
reporters,
muters,
followers: assertion.followers,
hops: assertion.hops,
});
}
}
// Strongest negative signal first.
out.sort((a, b) => b.reporters + b.muters - (a.reporters + a.muters));
return out;
}, [following, assertions, ignored]);
return {
alerts,
alertCount: alerts.length,
isLoading,
ignore: (pubkey: string) =>
setIgnored((prev) => (prev.includes(pubkey) ? prev : [...prev, pubkey])),
};
}

View file

@ -7394,6 +7394,14 @@ walletUi: {
sellerHint: 'This seller’s venue issues access passes',
},
trustUi: {
alertsTitle: 'Network alerts',
alertsDesc: 'Accounts you follow that trusted people have reported or muted.',
alertsEmpty: 'No alerts. We check the accounts you follow for trusted reports.',
alertsReported: 'Reported by {{count}} trusted people',
alertsMuted: 'Muted by {{count}} trusted people',
alertsIgnore: 'Ignore',
alertsUnfollow: 'Unfollow',
alertsLogin: 'Log in to see alerts for the accounts you follow.',
providerTitle: 'Provider',
providerDesc: 'Scores come from a provider you choose. The community provider is the default.',
useCommunity: 'Use community provider',

View file

@ -7394,6 +7394,14 @@ walletUi: {
sellerHint: 'El local de este vendedor emite pases de acceso',
},
trustUi: {
alertsTitle: 'Avisos de la red',
alertsDesc: 'Cuentas que sigues que personas de confianza han reportado o silenciado.',
alertsEmpty: 'Sin avisos. Revisamos las cuentas que sigues por reportes de confianza.',
alertsReported: 'Reportada por {{count}} personas de confianza',
alertsMuted: 'Silenciada por {{count}} personas de confianza',
alertsIgnore: 'Ignorar',
alertsUnfollow: 'Dejar de seguir',
alertsLogin: 'Inicia sesion para ver avisos de las cuentas que sigues.',
providerTitle: 'Proveedor',
providerDesc: 'Las puntuaciones vienen de un proveedor que elijas. El proveedor de la comunidad es el predeterminado.',
useCommunity: 'Usar proveedor de la comunidad',

View file

@ -0,0 +1,156 @@
import { useState } from 'react';
import { useSeoMeta } from '@unhead/react';
import { Link } from 'react-router-dom';
import { nip19 } from 'nostr-tools';
import { ShieldAlert, Flag, UserMinus, X } from 'lucide-react';
import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar';
import { Button } from '@/components/ui/button';
import { ReportDialog } from '@/components/ReportDialog';
import { useTranslation } from '@/contexts/language';
import { useCurrentUser } from '@/hooks/useCurrentUser';
import { useAuthor } from '@/hooks/useAuthor';
import { useNetworkAlerts } from '@/hooks/useNetworkAlerts';
import { useFollowActions } from '@/hooks/useFollowing';
import { useMuteUser } from '@/hooks/useMuteUser';
import { genUserName } from '@/lib/genUserName';
/**
* Accounts you follow that trusted people have reported or muted. A safety
* notice with actions the user chooses — ignore, unfollow, mute, report.
*/
export default function NetworkAlertsPage() {
const { t } = useTranslation();
useSeoMeta({
title: t('trustUi.alertsTitle'),
description: t('trustUi.alertsDesc'),
});
const { user } = useCurrentUser();
const { alerts, isLoading, ignore } = useNetworkAlerts();
return (
<div className="container max-w-2xl space-y-4 py-8">
<header>
<h1 className="flex items-center gap-2 text-2xl font-black uppercase tracking-wide text-white">
<ShieldAlert className="h-6 w-6 text-red-400" />
{t('trustUi.alertsTitle')}
</h1>
<p className="mt-1 text-sm text-gray-400">{t('trustUi.alertsDesc')}</p>
</header>
{!user ? (
<p className="text-sm text-muted-foreground">{t('trustUi.alertsLogin')}</p>
) : isLoading ? (
<p className="text-sm text-muted-foreground">{t('common.loading')}</p>
) : alerts.length === 0 ? (
<div className="rounded-2xl border border-white/10 bg-white/3 p-6 text-center text-sm text-muted-foreground">
{t('trustUi.alertsEmpty')}
</div>
) : (
<div className="space-y-3">
{alerts.map((alert) => (
<AlertRow
key={alert.pubkey}
pubkey={alert.pubkey}
reporters={alert.reporters}
muters={alert.muters}
onIgnore={() => ignore(alert.pubkey)}
/>
))}
</div>
)}
</div>
);
}
function AlertRow({
pubkey,
reporters,
muters,
onIgnore,
}: {
pubkey: string;
reporters: number;
muters: number;
onIgnore: () => void;
}) {
const { t } = useTranslation();
const { data: author } = useAuthor(pubkey);
const metadata = author?.metadata;
const name = metadata?.name || metadata?.display_name || genUserName(pubkey);
const { unfollow, isUnfollowing } = useFollowActions();
const muteUser = useMuteUser();
const [reportOpen, setReportOpen] = useState(false);
const profilePath = `/${nip19.npubEncode(pubkey)}`;
return (
<div className="rounded-2xl border border-red-500/25 bg-red-500/5 p-4">
<div className="flex items-start gap-3">
<Avatar className="h-10 w-10">
{metadata?.picture ? <AvatarImage src={metadata.picture} alt={name} /> : null}
<AvatarFallback>{name.slice(0, 2).toUpperCase()}</AvatarFallback>
</Avatar>
<div className="min-w-0 flex-1">
<Link to={profilePath} className="font-bold text-white hover:underline">
{name}
</Link>
<p className="text-xs text-gray-400">
{reporters > 0
? t('trustUi.alertsReported', { count: reporters })
: t('trustUi.alertsMuted', { count: muters })}
</p>
<div className="mt-2 flex flex-wrap gap-2">
<Button
size="sm"
variant="outline"
className="h-8 min-h-0 gap-1.5"
disabled={isUnfollowing}
onClick={() => unfollow(pubkey)}
>
<UserMinus className="h-3.5 w-3.5" />
{t('trustUi.alertsUnfollow')}
</Button>
<Button
size="sm"
variant="outline"
className="h-8 min-h-0"
disabled={muteUser.isPending}
onClick={() => muteUser.mutate(pubkey)}
>
{t('walletUi.trust.mute')}
</Button>
<Button
size="sm"
variant="outline"
className="h-8 min-h-0 gap-1.5 border-red-500/40 text-red-300 hover:bg-red-500/10"
onClick={() => setReportOpen(true)}
>
<Flag className="h-3.5 w-3.5" />
{t('walletUi.trust.flaggedReport')}
</Button>
<Button
size="sm"
variant="ghost"
className="h-8 min-h-0 gap-1.5 text-gray-400"
onClick={onIgnore}
>
<X className="h-3.5 w-3.5" />
{t('trustUi.alertsIgnore')}
</Button>
</div>
</div>
</div>
<ReportDialog
open={reportOpen}
onOpenChange={setReportOpen}
targetType="user"
targetPubkey={pubkey}
targetTitle={name}
/>
</div>
);
}