mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 06:34:24 +01:00
debug: add comprehensive logging to profile label resolution
Add detailed debug logs prefixed with [profile-labels] and [markdown-replace] to track the profile resolution flow: - Profile identifier extraction from content - Cache lookup and eventStore checks - Profile fetching from relays - Label updates when profiles resolve - Markdown URI replacement with profile labels This will help diagnose why profile names aren't resolving correctly.
This commit is contained in:
@@ -61,12 +61,14 @@ export const useMarkdownToHTML = (
|
|||||||
setProcessedMarkdown('')
|
setProcessedMarkdown('')
|
||||||
|
|
||||||
if (!markdown) {
|
if (!markdown) {
|
||||||
|
console.log(`[markdown-to-html] No markdown provided`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let isCancelled = false
|
let isCancelled = false
|
||||||
|
|
||||||
const processMarkdown = () => {
|
const processMarkdown = () => {
|
||||||
|
console.log(`[markdown-to-html] Processing markdown with ${profileLabels.size} profile labels`)
|
||||||
try {
|
try {
|
||||||
// Replace nostr URIs with profile labels (progressive) and article titles
|
// Replace nostr URIs with profile labels (progressive) and article titles
|
||||||
const processed = replaceNostrUrisInMarkdownWithProfileLabels(
|
const processed = replaceNostrUrisInMarkdownWithProfileLabels(
|
||||||
@@ -77,8 +79,10 @@ export const useMarkdownToHTML = (
|
|||||||
|
|
||||||
if (isCancelled) return
|
if (isCancelled) return
|
||||||
|
|
||||||
|
console.log(`[markdown-to-html] Markdown processed, length: ${processed.length}`)
|
||||||
setProcessedMarkdown(processed)
|
setProcessedMarkdown(processed)
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.error(`[markdown-to-html] Error processing markdown:`, error)
|
||||||
if (!isCancelled) {
|
if (!isCancelled) {
|
||||||
setProcessedMarkdown(markdown) // Fallback to original
|
setProcessedMarkdown(markdown) // Fallback to original
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,10 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
|||||||
// Ignore errors, continue processing other pointers
|
// Ignore errors, continue processing other pointers
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
console.log(`[profile-labels] Extracted ${result.length} profile identifiers from content:`, result.map(r => ({ encoded: r.encoded.slice(0, 20) + '...', pubkey: r.pubkey.slice(0, 16) + '...' })))
|
||||||
return result
|
return result
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.warn(`[profile-labels] Error extracting profile pointers:`, error)
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}, [content])
|
}, [content])
|
||||||
@@ -41,11 +43,13 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
|||||||
// Initialize labels synchronously from cache on first render to avoid delay
|
// Initialize labels synchronously from cache on first render to avoid delay
|
||||||
const initialLabels = useMemo(() => {
|
const initialLabels = useMemo(() => {
|
||||||
if (profileData.length === 0) {
|
if (profileData.length === 0) {
|
||||||
|
console.log(`[profile-labels] No profile data, returning empty labels`)
|
||||||
return new Map<string, string>()
|
return new Map<string, string>()
|
||||||
}
|
}
|
||||||
|
|
||||||
const allPubkeys = profileData.map(({ pubkey }) => pubkey)
|
const allPubkeys = profileData.map(({ pubkey }) => pubkey)
|
||||||
const cachedProfiles = loadCachedProfiles(allPubkeys)
|
const cachedProfiles = loadCachedProfiles(allPubkeys)
|
||||||
|
console.log(`[profile-labels] Loaded ${cachedProfiles.size} cached profiles out of ${allPubkeys.length} requested`)
|
||||||
const labels = new Map<string, string>()
|
const labels = new Map<string, string>()
|
||||||
|
|
||||||
profileData.forEach(({ encoded, pubkey }) => {
|
profileData.forEach(({ encoded, pubkey }) => {
|
||||||
@@ -56,19 +60,25 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
|||||||
const displayName = profileData.display_name || profileData.name || profileData.nip05
|
const displayName = profileData.display_name || profileData.name || profileData.nip05
|
||||||
if (displayName) {
|
if (displayName) {
|
||||||
labels.set(encoded, `@${displayName}`)
|
labels.set(encoded, `@${displayName}`)
|
||||||
|
console.log(`[profile-labels] Found cached name for ${encoded.slice(0, 20)}...: ${displayName}`)
|
||||||
} else {
|
} else {
|
||||||
// Use fallback npub display if profile has no name
|
// Use fallback npub display if profile has no name
|
||||||
const fallback = getNpubFallbackDisplay(pubkey)
|
const fallback = getNpubFallbackDisplay(pubkey)
|
||||||
labels.set(encoded, fallback)
|
labels.set(encoded, fallback)
|
||||||
|
console.log(`[profile-labels] Cached profile for ${encoded.slice(0, 20)}... has no name, using fallback: ${fallback}`)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (error) {
|
||||||
// Use fallback npub display if parsing fails
|
// Use fallback npub display if parsing fails
|
||||||
const fallback = getNpubFallbackDisplay(pubkey)
|
const fallback = getNpubFallbackDisplay(pubkey)
|
||||||
labels.set(encoded, fallback)
|
labels.set(encoded, fallback)
|
||||||
|
console.warn(`[profile-labels] Error parsing cached profile for ${encoded.slice(0, 20)}..., using fallback:`, error)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log(`[profile-labels] No cached profile for ${encoded.slice(0, 20)}... (pubkey: ${pubkey.slice(0, 16)}...)`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log(`[profile-labels] Initial labels from cache:`, Array.from(labels.entries()).map(([enc, label]) => ({ encoded: enc.slice(0, 20) + '...', label })))
|
||||||
return labels
|
return labels
|
||||||
}, [profileData])
|
}, [profileData])
|
||||||
|
|
||||||
@@ -98,9 +108,11 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
|||||||
|
|
||||||
const pubkeysToFetch: string[] = []
|
const pubkeysToFetch: string[] = []
|
||||||
|
|
||||||
|
console.log(`[profile-labels] Checking eventStore for ${profileData.length} profiles`)
|
||||||
profileData.forEach(({ encoded, pubkey }) => {
|
profileData.forEach(({ encoded, pubkey }) => {
|
||||||
// Skip if already resolved from initial cache
|
// Skip if already resolved from initial cache
|
||||||
if (labels.has(encoded)) {
|
if (labels.has(encoded)) {
|
||||||
|
console.log(`[profile-labels] Skipping ${encoded.slice(0, 20)}..., already has label from cache`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +122,12 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
|||||||
const eventStoreProfile = eventStore.getEvent(pubkey + ':0')
|
const eventStoreProfile = eventStore.getEvent(pubkey + ':0')
|
||||||
if (eventStoreProfile) {
|
if (eventStoreProfile) {
|
||||||
profileEvent = eventStoreProfile
|
profileEvent = eventStoreProfile
|
||||||
|
console.log(`[profile-labels] Found profile in eventStore for ${encoded.slice(0, 20)}...`)
|
||||||
|
} else {
|
||||||
|
console.log(`[profile-labels] Profile not in eventStore for ${encoded.slice(0, 20)}... (pubkey: ${pubkey.slice(0, 16)}...)`)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log(`[profile-labels] No eventStore available`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profileEvent) {
|
if (profileEvent) {
|
||||||
@@ -119,19 +136,23 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
|||||||
const displayName = profileData.display_name || profileData.name || profileData.nip05
|
const displayName = profileData.display_name || profileData.name || profileData.nip05
|
||||||
if (displayName) {
|
if (displayName) {
|
||||||
labels.set(encoded, `@${displayName}`)
|
labels.set(encoded, `@${displayName}`)
|
||||||
|
console.log(`[profile-labels] Set label from eventStore for ${encoded.slice(0, 20)}...: @${displayName}`)
|
||||||
} else {
|
} else {
|
||||||
// Use fallback npub display if profile has no name
|
// Use fallback npub display if profile has no name
|
||||||
const fallback = getNpubFallbackDisplay(pubkey)
|
const fallback = getNpubFallbackDisplay(pubkey)
|
||||||
labels.set(encoded, fallback)
|
labels.set(encoded, fallback)
|
||||||
|
console.log(`[profile-labels] Profile in eventStore for ${encoded.slice(0, 20)}... has no name, using fallback: ${fallback}`)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (error) {
|
||||||
// Use fallback npub display if parsing fails
|
// Use fallback npub display if parsing fails
|
||||||
const fallback = getNpubFallbackDisplay(pubkey)
|
const fallback = getNpubFallbackDisplay(pubkey)
|
||||||
labels.set(encoded, fallback)
|
labels.set(encoded, fallback)
|
||||||
|
console.warn(`[profile-labels] Error parsing eventStore profile for ${encoded.slice(0, 20)}..., using fallback:`, error)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No profile found yet, will use fallback after fetch or keep empty
|
// No profile found yet, will use fallback after fetch or keep empty
|
||||||
// We'll set fallback labels for missing profiles at the end
|
// We'll set fallback labels for missing profiles at the end
|
||||||
|
console.log(`[profile-labels] Adding ${encoded.slice(0, 20)}... to fetch queue`)
|
||||||
pubkeysToFetch.push(pubkey)
|
pubkeysToFetch.push(pubkey)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -141,16 +162,21 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
|||||||
if (!labels.has(encoded)) {
|
if (!labels.has(encoded)) {
|
||||||
const fallback = getNpubFallbackDisplay(pubkey)
|
const fallback = getNpubFallbackDisplay(pubkey)
|
||||||
labels.set(encoded, fallback)
|
labels.set(encoded, fallback)
|
||||||
|
console.log(`[profile-labels] Setting fallback label for ${encoded.slice(0, 20)}...: ${fallback}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log(`[profile-labels] Labels after checking cache and eventStore:`, Array.from(labels.entries()).map(([enc, label]) => ({ encoded: enc.slice(0, 20) + '...', label })))
|
||||||
|
console.log(`[profile-labels] Profiles to fetch: ${pubkeysToFetch.length}`, pubkeysToFetch.map(p => p.slice(0, 16) + '...'))
|
||||||
setProfileLabels(new Map(labels))
|
setProfileLabels(new Map(labels))
|
||||||
|
|
||||||
// Fetch missing profiles asynchronously
|
// Fetch missing profiles asynchronously
|
||||||
if (pubkeysToFetch.length > 0 && relayPool && eventStore) {
|
if (pubkeysToFetch.length > 0 && relayPool && eventStore) {
|
||||||
const pubkeysToFetchSet = new Set(pubkeysToFetch)
|
const pubkeysToFetchSet = new Set(pubkeysToFetch)
|
||||||
|
console.log(`[profile-labels] Fetching ${pubkeysToFetch.length} profiles from relays`)
|
||||||
fetchProfiles(relayPool, eventStore as unknown as IEventStore, pubkeysToFetch)
|
fetchProfiles(relayPool, eventStore as unknown as IEventStore, pubkeysToFetch)
|
||||||
.then((fetchedProfiles) => {
|
.then((fetchedProfiles) => {
|
||||||
|
console.log(`[profile-labels] Fetch completed, received ${fetchedProfiles.length} profiles`)
|
||||||
const updatedLabels = new Map(labels)
|
const updatedLabels = new Map(labels)
|
||||||
const fetchedProfilesByPubkey = new Map(fetchedProfiles.map(p => [p.pubkey, p]))
|
const fetchedProfilesByPubkey = new Map(fetchedProfiles.map(p => [p.pubkey, p]))
|
||||||
|
|
||||||
@@ -158,55 +184,79 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
|||||||
// Only update profiles that were in pubkeysToFetch (i.e., were being fetched)
|
// Only update profiles that were in pubkeysToFetch (i.e., were being fetched)
|
||||||
// This allows us to replace fallback labels with resolved names
|
// This allows us to replace fallback labels with resolved names
|
||||||
if (pubkeysToFetchSet.has(pubkey)) {
|
if (pubkeysToFetchSet.has(pubkey)) {
|
||||||
|
console.log(`[profile-labels] Processing fetched profile for ${encoded.slice(0, 20)}...`)
|
||||||
// First, try to use the profile from the returned array
|
// First, try to use the profile from the returned array
|
||||||
const fetchedProfile = fetchedProfilesByPubkey.get(pubkey)
|
const fetchedProfile = fetchedProfilesByPubkey.get(pubkey)
|
||||||
if (fetchedProfile) {
|
if (fetchedProfile) {
|
||||||
|
console.log(`[profile-labels] Found profile in fetch results for ${encoded.slice(0, 20)}...`)
|
||||||
try {
|
try {
|
||||||
const profileData = JSON.parse(fetchedProfile.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}`)
|
||||||
|
console.log(`[profile-labels] Updated label for ${encoded.slice(0, 20)}... to @${displayName}`)
|
||||||
} else {
|
} else {
|
||||||
// Use fallback npub display if profile has no name
|
// Use fallback npub display if profile has no name
|
||||||
const fallback = getNpubFallbackDisplay(pubkey)
|
const fallback = getNpubFallbackDisplay(pubkey)
|
||||||
updatedLabels.set(encoded, fallback)
|
updatedLabels.set(encoded, fallback)
|
||||||
|
console.log(`[profile-labels] Fetched profile for ${encoded.slice(0, 20)}... has no name, using fallback: ${fallback}`)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (error) {
|
||||||
// Use fallback npub display if parsing fails
|
// Use fallback npub display if parsing fails
|
||||||
const fallback = getNpubFallbackDisplay(pubkey)
|
const fallback = getNpubFallbackDisplay(pubkey)
|
||||||
updatedLabels.set(encoded, fallback)
|
updatedLabels.set(encoded, fallback)
|
||||||
|
console.warn(`[profile-labels] Error parsing fetched profile for ${encoded.slice(0, 20)}..., using fallback:`, error)
|
||||||
}
|
}
|
||||||
} else if (eventStore) {
|
} else if (eventStore) {
|
||||||
|
console.log(`[profile-labels] Profile not in fetch results, checking eventStore for ${encoded.slice(0, 20)}...`)
|
||||||
// Fallback: check eventStore (in case fetchProfiles stored but didn't return)
|
// Fallback: check eventStore (in case fetchProfiles stored but didn't return)
|
||||||
const profileEvent = eventStore.getEvent(pubkey + ':0')
|
const profileEvent = eventStore.getEvent(pubkey + ':0')
|
||||||
if (profileEvent) {
|
if (profileEvent) {
|
||||||
|
console.log(`[profile-labels] Found profile in eventStore after fetch for ${encoded.slice(0, 20)}...`)
|
||||||
try {
|
try {
|
||||||
const profileData = JSON.parse(profileEvent.content || '{}') as { name?: string; display_name?: string; nip05?: string }
|
const profileData = JSON.parse(profileEvent.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}`)
|
||||||
|
console.log(`[profile-labels] Updated label from eventStore for ${encoded.slice(0, 20)}... to @${displayName}`)
|
||||||
} else {
|
} else {
|
||||||
// Use fallback npub display if profile has no name
|
// Use fallback npub display if profile has no name
|
||||||
const fallback = getNpubFallbackDisplay(pubkey)
|
const fallback = getNpubFallbackDisplay(pubkey)
|
||||||
updatedLabels.set(encoded, fallback)
|
updatedLabels.set(encoded, fallback)
|
||||||
|
console.log(`[profile-labels] Profile in eventStore for ${encoded.slice(0, 20)}... has no name, using fallback: ${fallback}`)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (error) {
|
||||||
// Use fallback npub display if parsing fails
|
// Use fallback npub display if parsing fails
|
||||||
const fallback = getNpubFallbackDisplay(pubkey)
|
const fallback = getNpubFallbackDisplay(pubkey)
|
||||||
updatedLabels.set(encoded, fallback)
|
updatedLabels.set(encoded, fallback)
|
||||||
|
console.warn(`[profile-labels] Error parsing eventStore profile for ${encoded.slice(0, 20)}..., using fallback:`, error)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log(`[profile-labels] Profile not in eventStore after fetch for ${encoded.slice(0, 20)}..., keeping fallback`)
|
||||||
}
|
}
|
||||||
// If no profile found in eventStore, keep existing fallback
|
// If no profile found in eventStore, keep existing fallback
|
||||||
|
} else {
|
||||||
|
console.log(`[profile-labels] No eventStore available, keeping fallback for ${encoded.slice(0, 20)}...`)
|
||||||
}
|
}
|
||||||
// If no eventStore, keep existing fallback
|
// If no eventStore, keep existing fallback
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.log(`[profile-labels] Final labels after fetch:`, Array.from(updatedLabels.entries()).map(([enc, label]) => ({ encoded: enc.slice(0, 20) + '...', label })))
|
||||||
setProfileLabels(updatedLabels)
|
setProfileLabels(updatedLabels)
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((error) => {
|
||||||
|
console.error(`[profile-labels] Error fetching profiles:`, error)
|
||||||
// Silently handle fetch errors
|
// Silently handle fetch errors
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
if (pubkeysToFetch.length === 0) {
|
||||||
|
console.log(`[profile-labels] No profiles to fetch`)
|
||||||
|
} else if (!relayPool) {
|
||||||
|
console.log(`[profile-labels] No relayPool available, cannot fetch profiles`)
|
||||||
|
} else if (!eventStore) {
|
||||||
|
console.log(`[profile-labels] No eventStore available, cannot fetch profiles`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [profileData, eventStore, relayPool, initialLabels])
|
}, [profileData, eventStore, relayPool, initialLabels])
|
||||||
|
|
||||||
|
|||||||
@@ -315,12 +315,14 @@ export function replaceNostrUrisInMarkdownWithProfileLabels(
|
|||||||
profileLabels: Map<string, string> = new Map(),
|
profileLabels: Map<string, string> = new Map(),
|
||||||
articleTitles: Map<string, string> = new Map()
|
articleTitles: Map<string, string> = new Map()
|
||||||
): string {
|
): string {
|
||||||
|
console.log(`[markdown-replace] Replacing URIs with ${profileLabels.size} profile labels and ${articleTitles.size} article titles`)
|
||||||
return replaceNostrUrisSafely(markdown, (encoded) => {
|
return replaceNostrUrisSafely(markdown, (encoded) => {
|
||||||
const link = createNostrLink(encoded)
|
const link = createNostrLink(encoded)
|
||||||
|
|
||||||
// Check if we have a resolved profile name
|
// Check if we have a resolved profile name
|
||||||
if (profileLabels.has(encoded)) {
|
if (profileLabels.has(encoded)) {
|
||||||
const displayName = profileLabels.get(encoded)!
|
const displayName = profileLabels.get(encoded)!
|
||||||
|
console.log(`[markdown-replace] Using profile label for ${encoded.slice(0, 20)}...: ${displayName}`)
|
||||||
return `[${displayName}](${link})`
|
return `[${displayName}](${link})`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,6 +331,7 @@ export function replaceNostrUrisInMarkdownWithProfileLabels(
|
|||||||
const decoded = decode(encoded)
|
const decoded = decode(encoded)
|
||||||
if (decoded.type === 'naddr' && articleTitles.has(encoded)) {
|
if (decoded.type === 'naddr' && articleTitles.has(encoded)) {
|
||||||
const title = articleTitles.get(encoded)!
|
const title = articleTitles.get(encoded)!
|
||||||
|
console.log(`[markdown-replace] Using article title for ${encoded.slice(0, 20)}...: ${title}`)
|
||||||
return `[${title}](${link})`
|
return `[${title}](${link})`
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -337,6 +340,7 @@ export function replaceNostrUrisInMarkdownWithProfileLabels(
|
|||||||
|
|
||||||
// For other types or if not resolved, use default label (shortened npub format)
|
// For other types or if not resolved, use default label (shortened npub format)
|
||||||
const label = getNostrUriLabel(encoded)
|
const label = getNostrUriLabel(encoded)
|
||||||
|
console.log(`[markdown-replace] Using default label for ${encoded.slice(0, 20)}...: ${label}`)
|
||||||
return `[${label}](${link})`
|
return `[${label}](${link})`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user