feat: highlight (#346)

This commit is contained in:
Cody Tseng 2025-05-22 22:39:13 +08:00 committed by GitHub
parent ef0dc9e923
commit 6c91ba9eff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 197 additions and 29 deletions

View file

@ -60,7 +60,7 @@ export function isProtectedEvent(event: Event) {
}
export function isSupportedKind(kind: number) {
return [kinds.ShortTextNote, ExtendedKind.PICTURE].includes(kind)
return [kinds.ShortTextNote, kinds.Highlights, ExtendedKind.PICTURE].includes(kind)
}
export function getParentEventTag(event?: Event) {
@ -524,3 +524,16 @@ export function extractEmojiInfosFromTags(tags: string[][] = []) {
})
.filter(Boolean) as TEmoji[]
}
export function createFakeEvent(event: Partial<Event>): Event {
return {
id: '',
kind: 1,
pubkey: '',
content: '',
created_at: 0,
tags: [],
sig: '',
...event
}
}

View file

@ -52,3 +52,4 @@ export const toZapStreamLiveEvent = (event: Event) => {
return `https://zap.stream/${getSharableEventId(event)}`
}
export const toChachiChat = (relay: string, d: string) => `https://chachi.chat/${relay}/${d}`
export const toNjump = (id: string) => `https://njump.me/${id}`

View file

@ -29,6 +29,21 @@ export function generateEventIdFromETag(tag: string[]) {
}
}
export function generateEventIdFromATag(tag: string[]) {
try {
const [, coordinate, relay] = tag
const [kind, pubkey, identifier] = coordinate.split(':')
return nip19.naddrEncode({
kind: Number(kind),
pubkey,
identifier,
relays: relay ? [relay] : undefined
})
} catch {
return undefined
}
}
export function generateEventId(event: Pick<Event, 'id' | 'pubkey'>) {
const relay = client.getEventHint(event.id)
return nip19.neventEncode({ id: event.id, author: event.pubkey, relays: [relay] })