mirror of
https://github.com/dergigi/boris.git
synced 2025-12-18 15:14:20 +01:00
refactor(profiles): standardize profile name extraction and improve code quality
- Create centralized profileUtils.ts with extractProfileDisplayName function - Standardize profile name priority order: name || display_name || nip05 || fallback - Replace duplicate profile parsing code across 6+ locations - Add request deduplication to fetchProfiles to prevent duplicate relay requests - Simplify RAF batching logic in useProfileLabels with helper functions - Fix RichContent.tsx error when content.split() produces undefined parts - Remove unused eventCount variable in profileService - Fix React Hook dependency warnings by wrapping scheduleBatchedUpdate in useCallback
This commit is contained in:
@@ -4,6 +4,7 @@ import { nip19 } from 'nostr-tools'
|
||||
import { AddressPointer } from 'nostr-tools/nip19'
|
||||
import { NostrEvent, Filter } from 'nostr-tools'
|
||||
import { Helpers } from 'applesauce-core'
|
||||
import { extractProfileDisplayName } from '../src/utils/profileUtils'
|
||||
|
||||
const { getArticleTitle, getArticleImage, getArticleSummary } = Helpers
|
||||
|
||||
@@ -117,14 +118,14 @@ async function fetchArticleMetadata(naddr: string): Promise<ArticleMetadata | nu
|
||||
const summary = getArticleSummary(article) || 'Read this article on Boris'
|
||||
const image = getArticleImage(article) || '/boris-social-1200.png'
|
||||
|
||||
// Extract author name from profile
|
||||
// Extract author name from profile using centralized utility
|
||||
let authorName = pointer.pubkey.slice(0, 8) + '...'
|
||||
if (profileEvents.length > 0) {
|
||||
try {
|
||||
const profileData = JSON.parse(profileEvents[0].content)
|
||||
authorName = profileData.display_name || profileData.name || authorName
|
||||
} catch {
|
||||
// Use fallback
|
||||
const displayName = extractProfileDisplayName(profileEvents[0])
|
||||
if (displayName && !displayName.startsWith('@')) {
|
||||
authorName = displayName
|
||||
} else if (displayName) {
|
||||
authorName = displayName.substring(1) // Remove @ prefix
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user