mirror of
https://github.com/dergigi/boris.git
synced 2025-12-26 11:04:24 +01:00
fix: extract author pubkey directly from p tag in highlights
- Pass full highlight object to HighlightCitation component - Extract author pubkey from p tag as fallback if highlight.author not set - Add debug logging to track author resolution - Fix TypeScript type errors with proper guards - Ensure author profile resolution works correctly
This commit is contained in:
@@ -1,45 +1,54 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import React, { useState, useEffect, useMemo } from 'react'
|
||||
import { RelayPool } from 'applesauce-relay'
|
||||
import { useEventModel } from 'applesauce-react/hooks'
|
||||
import { Models } from 'applesauce-core'
|
||||
import { nip19 } from 'nostr-tools'
|
||||
import { fetchArticleTitle } from '../services/articleTitleResolver'
|
||||
import { Highlight } from '../types/highlights'
|
||||
|
||||
interface HighlightCitationProps {
|
||||
eventReference?: string
|
||||
urlReference?: string
|
||||
authorPubkey?: string
|
||||
highlight: Highlight
|
||||
relayPool?: RelayPool | null
|
||||
}
|
||||
|
||||
export const HighlightCitation: React.FC<HighlightCitationProps> = ({
|
||||
eventReference,
|
||||
urlReference,
|
||||
authorPubkey,
|
||||
highlight,
|
||||
relayPool
|
||||
}) => {
|
||||
const [articleTitle, setArticleTitle] = useState<string>()
|
||||
|
||||
// Extract author pubkey from p tag directly
|
||||
const authorPubkey = useMemo(() => {
|
||||
// First try the extracted author from highlight.author
|
||||
if (highlight.author) {
|
||||
return highlight.author
|
||||
}
|
||||
|
||||
// Fallback: extract directly from p tag
|
||||
const pTag = highlight.tags.find(t => t[0] === 'p')
|
||||
if (pTag && pTag[1]) {
|
||||
console.log('📝 Found author from p tag:', pTag[1])
|
||||
return pTag[1]
|
||||
}
|
||||
|
||||
return undefined
|
||||
}, [highlight.author, highlight.tags])
|
||||
|
||||
const authorProfile = useEventModel(Models.ProfileModel, authorPubkey ? [authorPubkey] : null)
|
||||
|
||||
// Debug: log the authorPubkey and profile
|
||||
useEffect(() => {
|
||||
if (authorPubkey) {
|
||||
console.log('📝 HighlightCitation - authorPubkey:', authorPubkey)
|
||||
console.log('📝 HighlightCitation - authorProfile:', authorProfile)
|
||||
}
|
||||
}, [authorPubkey, authorProfile])
|
||||
|
||||
useEffect(() => {
|
||||
if (!eventReference || !relayPool) {
|
||||
if (!highlight.eventReference || !relayPool) {
|
||||
return
|
||||
}
|
||||
|
||||
const loadTitle = async () => {
|
||||
try {
|
||||
if (!highlight.eventReference) return
|
||||
|
||||
// Convert eventReference to naddr if needed
|
||||
let naddr: string
|
||||
if (eventReference.includes(':')) {
|
||||
const parts = eventReference.split(':')
|
||||
if (highlight.eventReference.includes(':')) {
|
||||
const parts = highlight.eventReference.split(':')
|
||||
const kind = parseInt(parts[0])
|
||||
const pubkey = parts[1]
|
||||
const identifier = parts[2] || ''
|
||||
@@ -50,7 +59,7 @@ export const HighlightCitation: React.FC<HighlightCitationProps> = ({
|
||||
identifier
|
||||
})
|
||||
} else {
|
||||
naddr = eventReference
|
||||
naddr = highlight.eventReference
|
||||
}
|
||||
|
||||
const title = await fetchArticleTitle(relayPool, naddr)
|
||||
@@ -63,12 +72,12 @@ export const HighlightCitation: React.FC<HighlightCitationProps> = ({
|
||||
}
|
||||
|
||||
loadTitle()
|
||||
}, [eventReference, relayPool])
|
||||
}, [highlight.eventReference, relayPool])
|
||||
|
||||
const authorName = authorProfile?.name || authorProfile?.display_name
|
||||
|
||||
// For nostr-native content with article reference
|
||||
if (eventReference && (authorName || articleTitle)) {
|
||||
if (highlight.eventReference && (authorName || articleTitle)) {
|
||||
return (
|
||||
<div className="highlight-citation">
|
||||
— {authorName || 'Unknown'}{articleTitle ? `, ${articleTitle}` : ''}
|
||||
@@ -77,9 +86,9 @@ export const HighlightCitation: React.FC<HighlightCitationProps> = ({
|
||||
}
|
||||
|
||||
// For web URLs
|
||||
if (urlReference) {
|
||||
if (highlight.urlReference) {
|
||||
try {
|
||||
const url = new URL(urlReference)
|
||||
const url = new URL(highlight.urlReference)
|
||||
return (
|
||||
<div className="highlight-citation">
|
||||
— {url.hostname}
|
||||
|
||||
@@ -340,9 +340,7 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
||||
</blockquote>
|
||||
|
||||
<HighlightCitation
|
||||
eventReference={highlight.eventReference}
|
||||
urlReference={highlight.urlReference}
|
||||
authorPubkey={highlight.author}
|
||||
highlight={highlight}
|
||||
relayPool={relayPool}
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user