Move search to its own file, validate and search by nip05

This commit is contained in:
Jon Staab
2024-10-03 15:25:17 -07:00
parent 63761c91c8
commit d747424c28
6 changed files with 115 additions and 91 deletions
-29
View File
@@ -1,15 +1,11 @@
import {debounce} from 'throttle-debounce'
import {derived, readable} from 'svelte/store'
import {dec} from '@welshman/lib'
import {readProfile, displayProfile, displayPubkey, PROFILE} from '@welshman/util'
import type {SubscribeRequestWithHandlers} from "@welshman/net"
import type {PublishedProfile, TrustedEvent} from "@welshman/util"
import {deriveEventsMapped, withGetter} from '@welshman/store'
import {repository, load} from './core'
import {createSearch} from './util'
import {collection} from './collection'
import {loadRelaySelections} from './relaySelections'
import {wotGraph} from './wot'
export const profiles = withGetter(
deriveEventsMapped<PublishedProfile>(repository, {
@@ -49,31 +45,6 @@ export const {
},
})
export const searchProfiles = debounce(500, (search: string) => {
if (search.length > 2) {
load({filters: [{kinds: [PROFILE], search}]})
}
})
export const profileSearch = derived(profiles, $profiles =>
createSearch($profiles, {
onSearch: searchProfiles,
getValue: (profile: PublishedProfile) => profile.event.pubkey,
sortFn: ({score, item}) => {
if (score && score > 0.1) return -score!
const wotScore = wotGraph.get().get(item.event.pubkey) || 0
return score ? dec(score) * wotScore : -wotScore
},
fuseOptions: {
keys: ["name", "display_name", {name: "about", weight: 0.3}],
threshold: 0.3,
shouldSort: false,
},
}),
)
export const displayProfileByPubkey = (pubkey: string | undefined) =>
pubkey
? displayProfile(profilesByPubkey.get().get(pubkey), displayPubkey(pubkey))