|
|
|
@ -48,45 +48,56 @@ |
|
|
|
if (!userPubkey) return; |
|
|
|
if (!userPubkey) return; |
|
|
|
|
|
|
|
|
|
|
|
// Convert npub to hex for API calls |
|
|
|
// Convert npub to hex for API calls |
|
|
|
try { |
|
|
|
// NIP-07 may return either npub or hex, so check format first |
|
|
|
const decoded = nip19.decode(userPubkey); |
|
|
|
if (/^[0-9a-f]{64}$/i.test(userPubkey)) { |
|
|
|
if (decoded.type === 'npub') { |
|
|
|
// Already hex format |
|
|
|
userPubkeyHex = decoded.data as string; |
|
|
|
userPubkeyHex = userPubkey.toLowerCase(); |
|
|
|
contactPubkeys.add(userPubkeyHex); // Include user's own repos |
|
|
|
contactPubkeys.add(userPubkeyHex); // Include user's own repos |
|
|
|
|
|
|
|
} else { |
|
|
|
// Fetch user's kind 3 contact list |
|
|
|
// Try to decode as npub |
|
|
|
const contactEvents = await nostrClient.fetchEvents([ |
|
|
|
try { |
|
|
|
{ |
|
|
|
const decoded = nip19.decode(userPubkey); |
|
|
|
kinds: [KIND.CONTACT_LIST], |
|
|
|
if (decoded.type === 'npub') { |
|
|
|
authors: [userPubkeyHex], |
|
|
|
userPubkeyHex = decoded.data as string; |
|
|
|
limit: 1 |
|
|
|
contactPubkeys.add(userPubkeyHex); // Include user's own repos |
|
|
|
} |
|
|
|
} |
|
|
|
]); |
|
|
|
} catch (err) { |
|
|
|
|
|
|
|
// If decode fails, might still be hex or invalid - skip |
|
|
|
if (contactEvents.length > 0) { |
|
|
|
console.warn('Failed to decode user pubkey:', err); |
|
|
|
const contactEvent = contactEvents[0]; |
|
|
|
} |
|
|
|
// Extract pubkeys from 'p' tags |
|
|
|
} |
|
|
|
for (const tag of contactEvent.tags) { |
|
|
|
|
|
|
|
if (tag[0] === 'p' && tag[1]) { |
|
|
|
if (userPubkeyHex) { |
|
|
|
let pubkey = tag[1]; |
|
|
|
// Fetch user's kind 3 contact list |
|
|
|
// Try to decode if it's an npub |
|
|
|
const contactEvents = await nostrClient.fetchEvents([ |
|
|
|
try { |
|
|
|
{ |
|
|
|
const decoded = nip19.decode(pubkey); |
|
|
|
kinds: [KIND.CONTACT_LIST], |
|
|
|
if (decoded.type === 'npub') { |
|
|
|
authors: [userPubkeyHex], |
|
|
|
pubkey = decoded.data as string; |
|
|
|
limit: 1 |
|
|
|
} |
|
|
|
} |
|
|
|
} catch { |
|
|
|
]); |
|
|
|
// Assume it's already a hex pubkey |
|
|
|
|
|
|
|
} |
|
|
|
if (contactEvents.length > 0) { |
|
|
|
if (pubkey) { |
|
|
|
const contactEvent = contactEvents[0]; |
|
|
|
contactPubkeys.add(pubkey); |
|
|
|
// Extract pubkeys from 'p' tags |
|
|
|
|
|
|
|
for (const tag of contactEvent.tags) { |
|
|
|
|
|
|
|
if (tag[0] === 'p' && tag[1]) { |
|
|
|
|
|
|
|
let pubkey = tag[1]; |
|
|
|
|
|
|
|
// Try to decode if it's an npub |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const decoded = nip19.decode(pubkey); |
|
|
|
|
|
|
|
if (decoded.type === 'npub') { |
|
|
|
|
|
|
|
pubkey = decoded.data as string; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
// Assume it's already a hex pubkey |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (pubkey) { |
|
|
|
|
|
|
|
contactPubkeys.add(pubkey); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
|
|
|
|
console.warn('Failed to decode user pubkey:', err); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
} catch (err) { |
|
|
|
console.warn('Failed to load user or contacts:', err); |
|
|
|
console.warn('Failed to load user or contacts:', err); |
|
|
|
|