Compare commits
No commits in common. "e8833e72dbcc29c8df649c7d74599f5f42724bfd" and "3a45de9dbaf567f66901b115aeb0b4d36e1b3082" have entirely different histories.
e8833e72db
...
3a45de9dba
@ -8,7 +8,7 @@ import {
|
|||||||
} from '@nostr-dev-kit/ndk'
|
} from '@nostr-dev-kit/ndk'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { CommentEvent, ModDetails, UserRelaysType } from 'types'
|
import { CommentEvent, ModDetails, UserRelaysType } from 'types'
|
||||||
import { log, LogType, timeout } from 'utils'
|
import { log, LogType } from 'utils'
|
||||||
import { useNDKContext } from './useNDKContext'
|
import { useNDKContext } from './useNDKContext'
|
||||||
|
|
||||||
export const useComments = (mod: ModDetails) => {
|
export const useComments = (mod: ModDetails) => {
|
||||||
@ -20,11 +20,7 @@ export const useComments = (mod: ModDetails) => {
|
|||||||
|
|
||||||
const setupSubscription = async () => {
|
const setupSubscription = async () => {
|
||||||
// Find the mod author's relays.
|
// Find the mod author's relays.
|
||||||
|
const authorReadRelays = await getRelayListForUser(mod.author, ndk)
|
||||||
const authorReadRelays = await Promise.race([
|
|
||||||
getRelayListForUser(mod.author, ndk),
|
|
||||||
timeout(10 * 1000) // add a 10 sec timeout
|
|
||||||
])
|
|
||||||
.then((ndkRelayList) => {
|
.then((ndkRelayList) => {
|
||||||
if (ndkRelayList) return ndkRelayList[UserRelaysType.Read]
|
if (ndkRelayList) return ndkRelayList[UserRelaysType.Read]
|
||||||
return [] // Return an empty array if ndkRelayList is undefined
|
return [] // Return an empty array if ndkRelayList is undefined
|
||||||
@ -44,21 +40,13 @@ export const useComments = (mod: ModDetails) => {
|
|||||||
'#a': [mod.aTag]
|
'#a': [mod.aTag]
|
||||||
}
|
}
|
||||||
|
|
||||||
const relayUrls = new Set<string>()
|
|
||||||
|
|
||||||
ndk.pool.urls().forEach((relayUrl) => {
|
|
||||||
relayUrls.add(relayUrl)
|
|
||||||
})
|
|
||||||
|
|
||||||
authorReadRelays.forEach((relayUrl) => relayUrls.add(relayUrl))
|
|
||||||
|
|
||||||
subscription = ndk.subscribe(
|
subscription = ndk.subscribe(
|
||||||
filter,
|
filter,
|
||||||
{
|
{
|
||||||
closeOnEose: false,
|
closeOnEose: false,
|
||||||
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST
|
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST
|
||||||
},
|
},
|
||||||
NDKRelaySet.fromRelayUrls(Array.from(relayUrls), ndk)
|
NDKRelaySet.fromRelayUrls(authorReadRelays, ndk, true)
|
||||||
)
|
)
|
||||||
|
|
||||||
subscription.on('event', (ndkEvent) => {
|
subscription.on('event', (ndkEvent) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user