/** * User status fetcher (kind 30315, NIP-38) */ import { nostrClient } from '../nostr/applesauce-client.js'; import { config } from '../nostr/config.js'; import type { NostrEvent } from '../../types/nostr.js'; /** * Parse user status from kind 30315 event */ export function parseUserStatus(event: NostrEvent): string | null { if (event.kind !== 30315) return null; // Check for d tag with value "general" const dTag = event.tags.find((t) => t[0] === 'd' && t[1] === 'general'); if (!dTag) return null; return event.content || null; } /** * Fetch user status for a pubkey */ export async function fetchUserStatus( pubkey: string, relays?: string[] ): Promise { const relayList = relays || [ ...config.defaultRelays, ...config.profileRelays ]; const events = await nostrClient.fetchEvents( [ { kinds: [30315], authors: [pubkey], '#d': ['general'], limit: 1 } as any // NIP-38 uses #d tag for parameterized replaceable events ], relayList, { useCache: true, cacheResults: true } ); if (events.length === 0) return null; return parseUserStatus(events[0]); }