feat: support for follow packs

This commit is contained in:
codytseng
2025-11-27 00:02:13 +08:00
parent cdab9aa19e
commit b21855c294
27 changed files with 384 additions and 24 deletions

View File

@@ -4,7 +4,7 @@ import { Event, kinds } from 'nostr-tools'
import { buildATag } from './draft-event'
import { getReplaceableEventIdentifier } from './event'
import { getAmountFromInvoice, getLightningAddressFromProfile } from './lightning'
import { formatPubkey, pubkeyToNpub } from './pubkey'
import { formatPubkey, isValidPubkey, pubkeyToNpub } from './pubkey'
import { generateBech32IdFromETag, getEmojiInfosFromEmojiTags, tagNameEquals } from './tag'
import { isOnionUrl, isWebsocketUrl, normalizeHttpUrl, normalizeUrl } from './url'
@@ -403,3 +403,28 @@ export function getPinnedEventHexIdSetFromPinListEvent(event?: Event | null): Se
.slice(0, MAX_PINNED_NOTES) ?? []
)
}
export function getFollowPackInfoFromEvent(event: Event) {
let title: string | undefined
let description: string | undefined
let image: string | undefined
const pubkeys: string[] = []
event.tags.forEach(([tagName, tagValue]) => {
if (tagName === 'title') {
title = tagValue
} else if (tagName === 'description') {
description = tagValue
} else if (tagName === 'image') {
image = tagValue
} else if (tagName === 'p' && isValidPubkey(tagValue)) {
pubkeys.push(tagValue)
}
})
if (!title) {
title = event.tags.find(tagNameEquals('d'))?.[1] ?? 'Untitled Follow Pack'
}
return { title, description, image, pubkeys }
}