Merge pull request 'comment fetching in mod posts fix' (#102) from staging into master
All checks were successful
Release to Production / build_and_release (push) Successful in 45s
All checks were successful
Release to Production / build_and_release (push) Successful in 45s
Reviewed-on: #102
This commit is contained in:
commit
e8833e72db
@ -8,7 +8,7 @@ import {
|
||||
} from '@nostr-dev-kit/ndk'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { CommentEvent, ModDetails, UserRelaysType } from 'types'
|
||||
import { log, LogType } from 'utils'
|
||||
import { log, LogType, timeout } from 'utils'
|
||||
import { useNDKContext } from './useNDKContext'
|
||||
|
||||
export const useComments = (mod: ModDetails) => {
|
||||
@ -20,7 +20,11 @@ export const useComments = (mod: ModDetails) => {
|
||||
|
||||
const setupSubscription = async () => {
|
||||
// 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) => {
|
||||
if (ndkRelayList) return ndkRelayList[UserRelaysType.Read]
|
||||
return [] // Return an empty array if ndkRelayList is undefined
|
||||
@ -40,13 +44,21 @@ export const useComments = (mod: ModDetails) => {
|
||||
'#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(
|
||||
filter,
|
||||
{
|
||||
closeOnEose: false,
|
||||
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST
|
||||
},
|
||||
NDKRelaySet.fromRelayUrls(authorReadRelays, ndk, true)
|
||||
NDKRelaySet.fromRelayUrls(Array.from(relayUrls), ndk)
|
||||
)
|
||||
|
||||
subscription.on('event', (ndkEvent) => {
|
||||
|
Loading…
Reference in New Issue
Block a user