feat: 💨

This commit is contained in:
codytseng
2025-02-04 22:05:37 +08:00
parent b292b3e3b5
commit 33c1a8c215

View File

@@ -415,6 +415,7 @@ class ClientService extends EventTarget {
const profileEvents = events.sort((a, b) => b.created_at - a.created_at) const profileEvents = events.sort((a, b) => b.created_at - a.created_at)
profileEvents.forEach((profile) => this.profileEventDataloader.prime(profile.pubkey, profile)) profileEvents.forEach((profile) => this.profileEventDataloader.prime(profile.pubkey, profile))
await Promise.all(profileEvents.map((profile) => this.addUsernameToIndex(profile)))
return profileEvents.map((profileEvent) => getProfileFromProfileEvent(profileEvent)) return profileEvents.map((profileEvent) => getProfileFromProfileEvent(profileEvent))
} }
@@ -612,23 +613,26 @@ class ClientService extends EventTarget {
} }
if (profileEvent) { if (profileEvent) {
this.addUsernameToIndex(profileEvent) await this.addUsernameToIndex(profileEvent)
} }
return profileEvent return profileEvent
} }
private addUsernameToIndex(profileEvent: NEvent) { private async addUsernameToIndex(profileEvent: NEvent) {
try { try {
const profileObj = JSON.parse(profileEvent.content) const profileObj = JSON.parse(profileEvent.content)
const text = [ const text = [
profileObj.display_name?.trim() ?? '', profileObj.display_name?.trim() ?? '',
profileObj.name?.trim() ?? '', profileObj.name?.trim() ?? '',
profileObj.nip05?.split('@')[0]?.trim() ?? '' profileObj.nip05
?.split('@')
.map((s: string) => s.trim())
.join(' ') ?? ''
].join(' ') ].join(' ')
if (!text) return if (!text) return
this.userIndex.add(profileEvent.pubkey, text) await this.userIndex.addAsync(profileEvent.pubkey, text)
} catch { } catch {
return return
} }