refactor: post editor

This commit is contained in:
codytseng
2025-05-23 22:47:31 +08:00
parent 3d06421acb
commit 78725d1e88
31 changed files with 1603 additions and 766 deletions

View File

@@ -1,6 +1,6 @@
import { BIG_RELAY_URLS, ExtendedKind } from '@/constants'
import { getProfileFromProfileEvent, getRelayListFromRelayListEvent } from '@/lib/event'
import { formatPubkey, userIdToPubkey } from '@/lib/pubkey'
import { formatPubkey, pubkeyToNpub, userIdToPubkey } from '@/lib/pubkey'
import { extractPubkeysFromEventTags } from '@/lib/tag'
import { isLocalNetworkUrl, isWebsocketUrl, normalizeUrl } from '@/lib/url'
import { ISigner, TProfile, TRelayList } from '@/types'
@@ -693,7 +693,7 @@ class ClientService extends EventTarget {
try {
const pubkey = userIdToPubkey(id)
return { pubkey, username: formatPubkey(pubkey) }
return { pubkey, npub: pubkeyToNpub(pubkey) ?? '', username: formatPubkey(pubkey) }
} catch {
return undefined
}
@@ -833,11 +833,9 @@ class ClientService extends EventTarget {
this.relayListEventDataLoader.prime(event.pubkey, Promise.resolve(event))
}
async searchProfilesFromIndex(query: string, limit: number = 100) {
async searchNpubs(query: string, limit: number = 100) {
const result = await this.userIndex.searchAsync(query, { limit })
return Promise.all(result.map((pubkey) => this.fetchProfile(pubkey as string))).then(
(profiles) => profiles.filter(Boolean) as TProfile[]
)
return result.map((pubkey) => pubkeyToNpub(pubkey as string)).filter(Boolean) as string[]
}
async initUserIndexFromFollowings(pubkey: string, signal: AbortSignal) {