feat: sync relay sets
This commit is contained in:
parent
4343765aba
commit
7bd5b915eb
38 changed files with 1069 additions and 686 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { tagNameEquals } from '@/lib/tag'
|
||||
import { getFollowingsFromFollowListEvent } from '@/lib/event'
|
||||
import client from '@/services/client.service'
|
||||
import { Event } from 'nostr-tools'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
|
@ -18,13 +18,7 @@ export function useFetchFollowings(pubkey?: string | null) {
|
|||
if (!event) return
|
||||
|
||||
setFollowListEvent(event)
|
||||
setFollowings(
|
||||
event.tags
|
||||
.filter(tagNameEquals('p'))
|
||||
.map(([, pubkey]) => pubkey)
|
||||
.filter(Boolean)
|
||||
.reverse()
|
||||
)
|
||||
setFollowings(getFollowingsFromFollowListEvent(event))
|
||||
} finally {
|
||||
setIsFetching(false)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ export function useFetchRelayInfos(urls: string[]) {
|
|||
const [isFetching, setIsFetching] = useState(true)
|
||||
const [relayInfos, setRelayInfos] = useState<(TRelayInfo | undefined)[]>([])
|
||||
const [areAlgoRelays, setAreAlgoRelays] = useState(false)
|
||||
const [searchableRelayUrls, setSearchableRelayUrls] = useState<string[]>([])
|
||||
const urlsString = JSON.stringify(urls)
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -22,6 +23,15 @@ export function useFetchRelayInfos(urls: string[]) {
|
|||
const relayInfos = await client.fetchRelayInfos(urls)
|
||||
setRelayInfos(relayInfos)
|
||||
setAreAlgoRelays(relayInfos.every((relayInfo) => checkAlgoRelay(relayInfo)))
|
||||
setSearchableRelayUrls(
|
||||
relayInfos
|
||||
.map((relayInfo, index) => ({
|
||||
url: urls[index],
|
||||
searchable: relayInfo?.supported_nips?.includes(50)
|
||||
}))
|
||||
.filter((relayInfo) => relayInfo.searchable)
|
||||
.map((relayInfo) => relayInfo.url)
|
||||
)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
} finally {
|
||||
|
|
@ -33,5 +43,5 @@ export function useFetchRelayInfos(urls: string[]) {
|
|||
fetchRelayInfos()
|
||||
}, [urlsString])
|
||||
|
||||
return { relayInfos, isFetching, areAlgoRelays }
|
||||
return { relayInfos, isFetching, areAlgoRelays, searchableRelayUrls }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import { useRelaySettings } from '@/providers/RelaySettingsProvider'
|
||||
import { useFeed } from '@/providers/FeedProvider'
|
||||
import client from '@/services/client.service'
|
||||
import { TProfile } from '@/types'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useFetchRelayInfos } from './useFetchRelayInfos'
|
||||
|
||||
export function useSearchProfiles(search: string, limit: number) {
|
||||
const { searchableRelayUrls } = useRelaySettings()
|
||||
const { relayUrls } = useFeed()
|
||||
const { searchableRelayUrls } = useFetchRelayInfos(relayUrls)
|
||||
const [isFetching, setIsFetching] = useState(true)
|
||||
const [error, setError] = useState<Error | null>(null)
|
||||
const [profiles, setProfiles] = useState<TProfile[]>([])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue