This commit is contained in:
codytseng
2025-07-19 17:24:51 +08:00
parent 28ec943a52
commit 78725c1d14
45 changed files with 698 additions and 766 deletions

View File

@@ -1,11 +1,7 @@
import { BIG_RELAY_URLS, ExtendedKind } from '@/constants'
import {
extractServersFromTags,
getProfileFromProfileEvent,
getRelayListFromRelayListEvent
} from '@/lib/event'
import { getProfileFromEvent, getRelayListFromEvent } from '@/lib/event-metadata'
import { formatPubkey, pubkeyToNpub, userIdToPubkey } from '@/lib/pubkey'
import { extractPubkeysFromEventTags } from '@/lib/tag'
import { getPubkeysFromPTags, getServersFromServerTags } from '@/lib/tag'
import { isLocalNetworkUrl, isWebsocketUrl, normalizeUrl } from '@/lib/url'
import { ISigner, TProfile, TRelayList } from '@/types'
import { sha256 } from '@noble/hashes/sha2'
@@ -716,7 +712,7 @@ class ClientService extends EventTarget {
async fetchProfile(id: string, skipCache: boolean = false): Promise<TProfile | undefined> {
const profileEvent = await this.fetchProfileEvent(id, skipCache)
if (profileEvent) {
return getProfileFromProfileEvent(profileEvent)
return getProfileFromEvent(profileEvent)
}
try {
@@ -735,7 +731,7 @@ class ClientService extends EventTarget {
const profileEvents = events.sort((a, b) => b.created_at - a.created_at)
await Promise.all(profileEvents.map((profile) => this.addUsernameToIndex(profile)))
return profileEvents.map((profileEvent) => getProfileFromProfileEvent(profileEvent))
return profileEvents.map((profileEvent) => getProfileFromEvent(profileEvent))
}
async fetchRelayListEvent(pubkey: string) {
@@ -769,7 +765,7 @@ class ClientService extends EventTarget {
return relayEvents.map((event) => {
if (event) {
return getRelayListFromRelayListEvent(event)
return getRelayListFromEvent(event)
}
return {
write: BIG_RELAY_URLS,
@@ -821,7 +817,7 @@ class ClientService extends EventTarget {
async fetchFollowings(pubkey: string) {
const followListEvent = await this.fetchFollowListEvent(pubkey)
return followListEvent ? extractPubkeysFromEventTags(followListEvent.tags) : []
return followListEvent ? getPubkeysFromPTags(followListEvent.tags) : []
}
async fetchFollowingFavoriteRelays(pubkey: string) {
@@ -881,7 +877,7 @@ class ClientService extends EventTarget {
async fetchBlossomServerList(pubkey: string) {
const evt = await this.blossomServerListEventCache.fetch(pubkey)
return evt ? extractServersFromTags(evt.tags) : []
return evt ? getServersFromServerTags(evt.tags) : []
}
async fetchBlossomServerListEvent(pubkey: string) {

View File

@@ -1,5 +1,5 @@
import { BIG_RELAY_URLS, CODY_PUBKEY } from '@/constants'
import { extractZapInfoFromReceipt } from '@/lib/event'
import { getZapInfoFromEvent } from '@/lib/event-metadata'
import { TProfile } from '@/types'
import {
init,
@@ -141,7 +141,7 @@ class LightningService {
filter,
{
onevent: (evt) => {
const info = extractZapInfoFromReceipt(evt)
const info = getZapInfoFromEvent(evt)
if (!info) return
if (info.invoice === pr) {
@@ -154,7 +154,10 @@ class LightningService {
})
}
async payInvoice(invoice: string, closeOuterModel?: () => void): Promise<{ preimage: string; invoice: string } | null> {
async payInvoice(
invoice: string,
closeOuterModel?: () => void
): Promise<{ preimage: string; invoice: string } | null> {
if (this.provider) {
const { preimage } = await this.provider.sendPayment(invoice)
closeOuterModel?.()
@@ -189,7 +192,7 @@ class LightningService {
events.sort((a, b) => b.created_at - a.created_at)
const map = new Map<string, { pubkey: string; amount: number; comment?: string }>()
events.forEach((event) => {
const info = extractZapInfoFromReceipt(event)
const info = getZapInfoFromEvent(event)
if (!info || info.eventId || !info.senderPubkey || info.senderPubkey === CODY_PUBKEY) return
const { amount, comment, senderPubkey } = info

View File

@@ -1,5 +1,5 @@
import { extractEmojiInfosFromTags, extractZapInfoFromReceipt } from '@/lib/event'
import { tagNameEquals } from '@/lib/tag'
import { getZapInfoFromEvent } from '@/lib/event-metadata'
import { getEmojiInfosFromEmojiTags, tagNameEquals } from '@/lib/tag'
import client from '@/services/client.service'
import { TEmoji } from '@/types'
import dayjs from 'dayjs'
@@ -171,7 +171,7 @@ class NoteStatsService {
if (!emoji) return
if (/^:[a-zA-Z0-9_-]+:$/.test(evt.content)) {
const emojiInfos = extractEmojiInfosFromTags(evt.tags)
const emojiInfos = getEmojiInfosFromEmojiTags(evt.tags)
const shortcode = evt.content.split(':')[1]
const emojiInfo = emojiInfos.find((info) => info.shortcode === shortcode)
if (emojiInfo) {
@@ -199,7 +199,7 @@ class NoteStatsService {
}
private addZapByEvent(evt: Event) {
const info = extractZapInfoFromReceipt(evt)
const info = getZapInfoFromEvent(evt)
if (!info) return
const { originalEventId, senderPubkey, invoice, amount, comment } = info
if (!originalEventId || !senderPubkey) return