mirror of
https://github.com/dergigi/boris.git
synced 2026-02-17 13:04:59 +01:00
refactor: standardize profile display name fallbacks across codebase
- Add getProfileDisplayName() utility function for consistent profile name resolution - Update all components to use standardized npub fallback format instead of hex - Fix useProfileLabels hook to include fallback npub labels when profiles lack names - Refactor NostrMentionLink to eliminate duplication between npub/nprofile cases - Remove debug console.log statements from RichContent component - Update AuthorCard, SidebarHeader, HighlightItem, Support, BlogPostCard, ResolvedMention, and useEventLoader to use new utilities
This commit is contained in:
@@ -6,6 +6,7 @@ import { ReadableContent } from '../services/readerService'
|
||||
import { eventManager } from '../services/eventManager'
|
||||
import { fetchProfiles } from '../services/profileService'
|
||||
import { useDocumentTitle } from './useDocumentTitle'
|
||||
import { getNpubFallbackDisplay } from '../utils/nostrUriResolver'
|
||||
|
||||
interface UseEventLoaderProps {
|
||||
eventId?: string
|
||||
@@ -40,7 +41,7 @@ export function useEventLoader({
|
||||
// Initial title
|
||||
let title = `Note (${event.kind})`
|
||||
if (event.kind === 1) {
|
||||
title = `Note by @${event.pubkey.slice(0, 8)}...`
|
||||
title = `Note by ${getNpubFallbackDisplay(event.pubkey)}`
|
||||
}
|
||||
|
||||
// Emit immediately
|
||||
@@ -83,7 +84,7 @@ export function useEventLoader({
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (resolved) {
|
||||
const updatedTitle = `Note by @${resolved}`
|
||||
setCurrentTitle(updatedTitle)
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Helpers, IEventStore } from 'applesauce-core'
|
||||
import { getContentPointers } from 'applesauce-factory/helpers'
|
||||
import { RelayPool } from 'applesauce-relay'
|
||||
import { fetchProfiles, loadCachedProfiles } from '../services/profileService'
|
||||
import { getNpubFallbackDisplay } from '../utils/nostrUriResolver'
|
||||
|
||||
const { getPubkeyFromDecodeResult, encodeDecodeResult } = Helpers
|
||||
|
||||
@@ -55,9 +56,15 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
||||
const displayName = profileData.display_name || profileData.name || profileData.nip05
|
||||
if (displayName) {
|
||||
labels.set(encoded, `@${displayName}`)
|
||||
} else {
|
||||
// Use fallback npub display if profile has no name
|
||||
const fallback = getNpubFallbackDisplay(pubkey)
|
||||
labels.set(encoded, fallback)
|
||||
}
|
||||
} catch {
|
||||
// Ignore parsing errors, will fetch later
|
||||
// Use fallback npub display if parsing fails
|
||||
const fallback = getNpubFallbackDisplay(pubkey)
|
||||
labels.set(encoded, fallback)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -113,16 +120,30 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
||||
if (displayName) {
|
||||
labels.set(encoded, `@${displayName}`)
|
||||
} else {
|
||||
pubkeysToFetch.push(pubkey)
|
||||
// Use fallback npub display if profile has no name
|
||||
const fallback = getNpubFallbackDisplay(pubkey)
|
||||
labels.set(encoded, fallback)
|
||||
}
|
||||
} catch {
|
||||
pubkeysToFetch.push(pubkey)
|
||||
// Use fallback npub display if parsing fails
|
||||
const fallback = getNpubFallbackDisplay(pubkey)
|
||||
labels.set(encoded, fallback)
|
||||
}
|
||||
} else {
|
||||
// No profile found yet, will use fallback after fetch or keep empty
|
||||
// We'll set fallback labels for missing profiles at the end
|
||||
pubkeysToFetch.push(pubkey)
|
||||
}
|
||||
})
|
||||
|
||||
// Set fallback labels for profiles that weren't found
|
||||
profileData.forEach(({ encoded, pubkey }) => {
|
||||
if (!labels.has(encoded)) {
|
||||
const fallback = getNpubFallbackDisplay(pubkey)
|
||||
labels.set(encoded, fallback)
|
||||
}
|
||||
})
|
||||
|
||||
setProfileLabels(new Map(labels))
|
||||
|
||||
// Fetch missing profiles asynchronously
|
||||
@@ -142,9 +163,15 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
||||
const displayName = profileData.display_name || profileData.name || profileData.nip05
|
||||
if (displayName) {
|
||||
updatedLabels.set(encoded, `@${displayName}`)
|
||||
} else {
|
||||
// Use fallback npub display if profile has no name
|
||||
const fallback = getNpubFallbackDisplay(pubkey)
|
||||
updatedLabels.set(encoded, fallback)
|
||||
}
|
||||
} catch {
|
||||
// Ignore parsing errors
|
||||
// Use fallback npub display if parsing fails
|
||||
const fallback = getNpubFallbackDisplay(pubkey)
|
||||
updatedLabels.set(encoded, fallback)
|
||||
}
|
||||
} else if (eventStore) {
|
||||
// Fallback: check eventStore (in case fetchProfiles stored but didn't return)
|
||||
@@ -155,11 +182,25 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
||||
const displayName = profileData.display_name || profileData.name || profileData.nip05
|
||||
if (displayName) {
|
||||
updatedLabels.set(encoded, `@${displayName}`)
|
||||
} else {
|
||||
// Use fallback npub display if profile has no name
|
||||
const fallback = getNpubFallbackDisplay(pubkey)
|
||||
updatedLabels.set(encoded, fallback)
|
||||
}
|
||||
} catch {
|
||||
// Ignore parsing errors
|
||||
// Use fallback npub display if parsing fails
|
||||
const fallback = getNpubFallbackDisplay(pubkey)
|
||||
updatedLabels.set(encoded, fallback)
|
||||
}
|
||||
} else {
|
||||
// No profile found, use fallback
|
||||
const fallback = getNpubFallbackDisplay(pubkey)
|
||||
updatedLabels.set(encoded, fallback)
|
||||
}
|
||||
} else {
|
||||
// No eventStore, use fallback
|
||||
const fallback = getNpubFallbackDisplay(pubkey)
|
||||
updatedLabels.set(encoded, fallback)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user