mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 14:44:26 +01:00
fix: use fetchedProfiles array directly instead of only checking eventStore
- fetchProfiles returns profiles that we should use immediately - Check returned array first, then fallback to eventStore lookup - Fixes issue where profiles were returned but not used for resolution
This commit is contained in:
@@ -86,45 +86,67 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
|||||||
.then((fetchedProfiles) => {
|
.then((fetchedProfiles) => {
|
||||||
console.log('[npub-resolve] fetchProfiles returned', fetchedProfiles.length, 'profiles')
|
console.log('[npub-resolve] fetchProfiles returned', fetchedProfiles.length, 'profiles')
|
||||||
|
|
||||||
// Re-check eventStore for all profiles (including ones we just fetched)
|
// First, use the profiles returned from fetchProfiles directly
|
||||||
// This ensures we get profiles even if fetchProfiles didn't return them in the array
|
|
||||||
const updatedLabels = new Map(labels)
|
const updatedLabels = new Map(labels)
|
||||||
let foundInStore = 0
|
const fetchedProfilesByPubkey = new Map(fetchedProfiles.map(p => [p.pubkey, p]))
|
||||||
|
|
||||||
|
let resolvedFromArray = 0
|
||||||
|
let resolvedFromStore = 0
|
||||||
let withNames = 0
|
let withNames = 0
|
||||||
let withoutNames = 0
|
let withoutNames = 0
|
||||||
let missingFromStore = 0
|
let missingFromStore = 0
|
||||||
|
|
||||||
profileData.forEach(({ encoded, pubkey }) => {
|
profileData.forEach(({ encoded, pubkey }) => {
|
||||||
if (!updatedLabels.has(encoded) && eventStore) {
|
if (!updatedLabels.has(encoded)) {
|
||||||
const profileEvent = eventStore.getEvent(pubkey + ':0')
|
// First, try to use the profile from the returned array
|
||||||
if (profileEvent) {
|
const fetchedProfile = fetchedProfilesByPubkey.get(pubkey)
|
||||||
foundInStore++
|
if (fetchedProfile) {
|
||||||
|
resolvedFromArray++
|
||||||
try {
|
try {
|
||||||
const profileData = JSON.parse(profileEvent.content || '{}') as { name?: string; display_name?: string; nip05?: string }
|
const profileData = JSON.parse(fetchedProfile.content || '{}') as { name?: string; display_name?: string; nip05?: string }
|
||||||
const displayName = profileData.display_name || profileData.name || profileData.nip05
|
const displayName = profileData.display_name || profileData.name || profileData.nip05
|
||||||
if (displayName) {
|
if (displayName) {
|
||||||
updatedLabels.set(encoded, `@${displayName}`)
|
updatedLabels.set(encoded, `@${displayName}`)
|
||||||
withNames++
|
withNames++
|
||||||
console.log('[npub-resolve] Resolved profile:', encoded.slice(0, 30) + '...', '->', displayName)
|
console.log('[npub-resolve] Resolved from fetched array:', encoded.slice(0, 30) + '...', '->', displayName)
|
||||||
} else {
|
} else {
|
||||||
withoutNames++
|
withoutNames++
|
||||||
if (withoutNames <= 3) { // Log first few for debugging
|
if (withoutNames <= 3) {
|
||||||
console.log('[npub-resolve] Profile event found but no name/display_name/nip05:', encoded.slice(0, 30) + '...', 'content keys:', Object.keys(profileData))
|
console.log('[npub-resolve] Fetched profile has no name/display_name/nip05:', encoded.slice(0, 30) + '...', 'content keys:', Object.keys(profileData))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[npub-resolve] Error parsing profile event for', encoded.slice(0, 30) + '...', err)
|
console.error('[npub-resolve] Error parsing fetched profile for', encoded.slice(0, 30) + '...', err)
|
||||||
|
}
|
||||||
|
} else if (eventStore) {
|
||||||
|
// Fallback: check eventStore (in case fetchProfiles stored but didn't return)
|
||||||
|
const profileEvent = eventStore.getEvent(pubkey + ':0')
|
||||||
|
if (profileEvent) {
|
||||||
|
resolvedFromStore++
|
||||||
|
try {
|
||||||
|
const profileData = JSON.parse(profileEvent.content || '{}') as { name?: string; display_name?: string; nip05?: string }
|
||||||
|
const displayName = profileData.display_name || profileData.name || profileData.nip05
|
||||||
|
if (displayName) {
|
||||||
|
updatedLabels.set(encoded, `@${displayName}`)
|
||||||
|
withNames++
|
||||||
|
console.log('[npub-resolve] Resolved from eventStore:', encoded.slice(0, 30) + '...', '->', displayName)
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[npub-resolve] Error parsing profile event for', encoded.slice(0, 30) + '...', err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
missingFromStore++
|
||||||
|
if (missingFromStore <= 3) {
|
||||||
|
console.log('[npub-resolve] Profile not found in array or eventStore:', pubkey.slice(0, 16) + '...')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
missingFromStore++
|
missingFromStore++
|
||||||
if (missingFromStore <= 3) { // Log first few for debugging
|
|
||||||
console.log('[npub-resolve] Profile not in eventStore after fetch:', pubkey.slice(0, 16) + '...')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('[npub-resolve] After fetch - resolved:', updatedLabels.size, 'total | found in store:', foundInStore, '| with names:', withNames, '| without names:', withoutNames, '| missing:', missingFromStore, '| out of', profileData.length)
|
console.log('[npub-resolve] After fetch - resolved:', updatedLabels.size, 'total | from array:', resolvedFromArray, '| from store:', resolvedFromStore, '| with names:', withNames, '| without names:', withoutNames, '| missing:', missingFromStore, '| out of', profileData.length)
|
||||||
setProfileLabels(updatedLabels)
|
setProfileLabels(updatedLabels)
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|||||||
Reference in New Issue
Block a user