feat: add kind:1111 events to feed

This commit is contained in:
codytseng
2025-05-24 16:53:14 +08:00
parent 06f9ea984f
commit 7552499a76
5 changed files with 52 additions and 32 deletions

View File

@@ -0,0 +1,34 @@
import { Button } from '@/components/ui/button'
import { getSharableEventId } from '@/lib/event'
import { cn } from '@/lib/utils'
import { Check, Copy } from 'lucide-react'
import { Event } from 'nostr-tools'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
export function UnknownNote({ event, className }: { event: Event; className?: string }) {
const { t } = useTranslation()
const [isCopied, setIsCopied] = useState(false)
return (
<div
className={cn(
'flex flex-col gap-2 items-center text-muted-foreground font-medium my-4',
className
)}
>
<div>{t('Cannot handle event of kind k', { k: event.kind })}</div>
<Button
onClick={(e) => {
e.stopPropagation()
navigator.clipboard.writeText(getSharableEventId(event))
setIsCopied(true)
setTimeout(() => setIsCopied(false), 2000)
}}
variant="outline"
>
{isCopied ? <Check /> : <Copy />} Copy event ID
</Button>
</div>
)
}

View File

@@ -3,7 +3,8 @@ import {
extractImageInfosFromEventTags, extractImageInfosFromEventTags,
getParentEventId, getParentEventId,
getUsingClient, getUsingClient,
isPictureEvent isPictureEvent,
isSupportedKind
} from '@/lib/event' } from '@/lib/event'
import { toNote } from '@/lib/link' import { toNote } from '@/lib/link'
import { Event, kinds } from 'nostr-tools' import { Event, kinds } from 'nostr-tools'
@@ -16,6 +17,7 @@ import ParentNotePreview from '../ParentNotePreview'
import UserAvatar from '../UserAvatar' import UserAvatar from '../UserAvatar'
import Username from '../Username' import Username from '../Username'
import Highlight from './Highlight' import Highlight from './Highlight'
import { UnknownNote } from './UnknownNote'
export default function Note({ export default function Note({
event, event,
@@ -30,10 +32,7 @@ export default function Note({
}) { }) {
const { push } = useSecondaryPage() const { push } = useSecondaryPage()
const parentEventId = useMemo( const parentEventId = useMemo(
() => () => (hideParentNotePreview ? undefined : getParentEventId(event)),
!hideParentNotePreview && event.kind === kinds.ShortTextNote
? getParentEventId(event)
: undefined,
[event, hideParentNotePreview] [event, hideParentNotePreview]
) )
const imageInfos = useMemo( const imageInfos = useMemo(
@@ -79,8 +78,10 @@ export default function Note({
)} )}
{event.kind === kinds.Highlights ? ( {event.kind === kinds.Highlights ? (
<Highlight className="mt-2" event={event} /> <Highlight className="mt-2" event={event} />
) : ( ) : isSupportedKind(event.kind) ? (
<Content className="mt-2" event={event} /> <Content className="mt-2" event={event} />
) : (
<UnknownNote className="mt-2" event={event} />
)} )}
{imageInfos.length > 0 && <ImageGallery images={imageInfos} />} {imageInfos.length > 0 && <ImageGallery images={imageInfos} />}
</div> </div>

View File

@@ -1,12 +1,8 @@
import { Button } from '@/components/ui/button'
import { Separator } from '@/components/ui/separator' import { Separator } from '@/components/ui/separator'
import { getSharableEventId } from '@/lib/event'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
import { Check, Copy } from 'lucide-react'
import { Event } from 'nostr-tools' import { Event } from 'nostr-tools'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { FormattedTimestamp } from '../FormattedTimestamp' import { FormattedTimestamp } from '../FormattedTimestamp'
import { UnknownNote } from '../Note/UnknownNote'
import UserAvatar from '../UserAvatar' import UserAvatar from '../UserAvatar'
import Username from '../Username' import Username from '../Username'
import RepostDescription from './RepostDescription' import RepostDescription from './RepostDescription'
@@ -22,9 +18,6 @@ export default function UnknownNoteCard({
embedded?: boolean embedded?: boolean
reposter?: string reposter?: string
}) { }) {
const { t } = useTranslation()
const [isCopied, setIsCopied] = useState(false)
return ( return (
<div className={className}> <div className={className}>
<div className={cn(embedded ? 'p-2 sm:p-3 border rounded-lg' : 'px-4 py-3')}> <div className={cn(embedded ? 'p-2 sm:p-3 border rounded-lg' : 'px-4 py-3')}>
@@ -44,20 +37,7 @@ export default function UnknownNoteCard({
</div> </div>
</div> </div>
</div> </div>
<div className="flex flex-col gap-2 items-center text-muted-foreground font-medium my-4"> <UnknownNote event={event} />
<div>{t('Cannot handle event of kind k', { k: event.kind })}</div>
<Button
onClick={(e) => {
e.stopPropagation()
navigator.clipboard.writeText(getSharableEventId(event))
setIsCopied(true)
setTimeout(() => setIsCopied(false), 2000)
}}
variant="outline"
>
{isCopied ? <Check /> : <Copy />} Copy event ID
</Button>
</div>
</div> </div>
{!embedded && <Separator />} {!embedded && <Separator />}
</div> </div>

View File

@@ -110,7 +110,7 @@ export default function NoteList({
subRequests.push({ subRequests.push({
urls: myRelayList.write.concat(BIG_RELAY_URLS).slice(0, 5), urls: myRelayList.write.concat(BIG_RELAY_URLS).slice(0, 5),
filter: { filter: {
kinds: [kinds.ShortTextNote, kinds.Repost, kinds.Highlights], kinds: [kinds.ShortTextNote, kinds.Repost, kinds.Highlights, ExtendedKind.COMMENT],
authors: [pubkey], authors: [pubkey],
'#p': [author], '#p': [author],
limit: LIMIT limit: LIMIT
@@ -119,7 +119,7 @@ export default function NoteList({
subRequests.push({ subRequests.push({
urls: targetRelayList.write.concat(BIG_RELAY_URLS).slice(0, 5), urls: targetRelayList.write.concat(BIG_RELAY_URLS).slice(0, 5),
filter: { filter: {
kinds: [kinds.ShortTextNote, kinds.Repost, kinds.Highlights], kinds: [kinds.ShortTextNote, kinds.Repost, kinds.Highlights, ExtendedKind.COMMENT],
authors: [author], authors: [author],
'#p': [pubkey], '#p': [pubkey],
limit: LIMIT limit: LIMIT
@@ -135,7 +135,7 @@ export default function NoteList({
kinds: kinds:
filterType === 'pictures' filterType === 'pictures'
? [ExtendedKind.PICTURE] ? [ExtendedKind.PICTURE]
: [kinds.ShortTextNote, kinds.Repost, kinds.Highlights], : [kinds.ShortTextNote, kinds.Repost, kinds.Highlights, ExtendedKind.COMMENT],
limit: areAlgoRelays ? ALGO_LIMIT : LIMIT limit: areAlgoRelays ? ALGO_LIMIT : LIMIT
} }
if (relayUrls.length === 0 && (_filter.authors?.length || author)) { if (relayUrls.length === 0 && (_filter.authors?.length || author)) {

View File

@@ -61,7 +61,12 @@ export function isProtectedEvent(event: Event) {
} }
export function isSupportedKind(kind: number) { export function isSupportedKind(kind: number) {
return [kinds.ShortTextNote, kinds.Highlights, ExtendedKind.PICTURE].includes(kind) return [
kinds.ShortTextNote,
kinds.Highlights,
ExtendedKind.PICTURE,
ExtendedKind.COMMENT
].includes(kind)
} }
export function getParentEventTag(event?: Event) { export function getParentEventTag(event?: Event) {