feat: optimize the display effect of other kinds of events

This commit is contained in:
codytseng
2025-02-13 22:56:09 +08:00
parent 5e3fd93a23
commit 73b38d37e7
17 changed files with 719 additions and 66 deletions

View File

@@ -45,6 +45,10 @@ export function isProtectedEvent(event: Event) {
return event.tags.some(([tagName]) => tagName === '-')
}
export function isSupportedKind(kind: number) {
return [kinds.ShortTextNote, PICTURE_EVENT_KIND].includes(kind)
}
export function getParentEventId(event?: Event) {
if (!event || !isReplyNoteEvent(event)) return undefined
const tag = event.tags.find(isReplyETag) ?? event.tags.find(tagNameEquals('e'))
@@ -81,7 +85,7 @@ export function getEventCoordinate(event: Event) {
}
export function getSharableEventId(event: Event) {
const hints = client.getEventHints(event.id).slice(0, 3)
const hints = client.getEventHints(event.id).slice(0, 2)
if (isReplaceable(event.kind)) {
const identifier = event.tags.find(tagNameEquals('d'))?.[1] ?? ''
return nip19.naddrEncode({ pubkey: event.pubkey, kind: event.kind, identifier, relays: hints })

View File

@@ -1,9 +1,12 @@
import client from '@/services/client.service'
import { Event, nip19 } from 'nostr-tools'
import { getSharableEventId } from './event'
export const toHome = () => '/'
export const toNote = (eventOrId: Pick<Event, 'id' | 'pubkey'> | string) => {
if (typeof eventOrId === 'string') return `/notes/${eventOrId}`
const nevent = nip19.neventEncode({ id: eventOrId.id, author: eventOrId.pubkey })
const relay = client.getEventHint(eventOrId.id)
const nevent = nip19.neventEncode({ id: eventOrId.id, author: eventOrId.pubkey, relays: [relay] })
return `/notes/${nevent}`
}
export const toNoteList = ({ hashtag, search }: { hashtag?: string; search?: string }) => {
@@ -40,7 +43,10 @@ export const toProfileEditor = () => '/profile-editor'
export const toRelay = (url: string) => `/relays/${encodeURIComponent(url)}`
export const toMuteList = () => '/mutes'
export const toNoStrudelProfile = (id: string) => `https://nostrudel.ninja/#/u/${id}`
export const toNoStrudelNote = (id: string) => `https://nostrudel.ninja/#/n/${id}`
export const toNoStrudelArticle = (id: string) => `https://nostrudel.ninja/#/articles/${id}`
export const toNoStrudelStream = (id: string) => `https://nostrudel.ninja/#/streams/${id}`
export const toHablaLongFormArticle = (event: Event) => {
return `https://habla.news/a/${getSharableEventId(event)}`
}
export const toZapStreamLiveEvent = (event: Event) => {
return `https://zap.stream/${getSharableEventId(event)}`
}
export const toChachiChat = (relay: string, d: string) => `https://chachi.chat/${relay}/${d}`