import { useQuery } from '@tanstack/react-query'; import { useNostr } from '@nostrify/react'; import { useCurrentUser } from './useCurrentUser'; import { onlyVerified } from '@/lib/verifyEvents'; import { getLocalMutes } from '@/lib/localMutes'; /** NIP-51 mute list. */ export const MUTE_LIST_KIND = 10000; /** * The viewer's muted pubkeys: their kind-10000 list plus any optimistic mutes * made on this device. Returns an empty set when logged out. */ export function useMuteList() { const { nostr } = useNostr(); const { user } = useCurrentUser(); const pubkey = user?.pubkey; return useQuery({ queryKey: ['mute-list', pubkey], enabled: !!pubkey, staleTime: 5 * 60 * 1000, queryFn: async (c): Promise> => { const set = getLocalMutes(); if (!pubkey) return set; const signal = AbortSignal.any([c.signal, AbortSignal.timeout(8000)]); const events = onlyVerified(await nostr.query( [{ kinds: [MUTE_LIST_KIND], authors: [pubkey], limit: 1 }], { signal }, )); for (const tag of events[0]?.tags ?? []) { if (tag[0] === 'p' && tag[1]) set.add(tag[1]); } return set; }, }); }