Compare commits

...

4 Commits

Author SHA1 Message Date
bc782c775a Merge pull request 'comment-fix' (#101) from comment-fix into staging
All checks were successful
Release to Staging / build_and_release (push) Successful in 45s
Reviewed-on: #101
Reviewed-by: enes <enes@noreply.git.nostrdev.com>
2024-10-25 08:45:16 +00:00
daniyal
d3c2d5fe7a chore: quick fix 2024-10-24 21:08:40 +05:00
daniyal
d96e5088b8 fix: add timeout in getting user's relay and also pass ndk pool's relays in relayset 2024-10-24 21:07:18 +05:00
daniyal
9aa57c1adf fix: no need to pass relay set to subscribe function, just include p tag with authors pubkey 2024-10-24 20:29:57 +05:00

View File

@ -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 } from 'utils' import { log, LogType, timeout } from 'utils'
import { useNDKContext } from './useNDKContext' import { useNDKContext } from './useNDKContext'
export const useComments = (mod: ModDetails) => { export const useComments = (mod: ModDetails) => {
@ -20,7 +20,11 @@ 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
@ -40,13 +44,21 @@ 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(authorReadRelays, ndk, true) NDKRelaySet.fromRelayUrls(Array.from(relayUrls), ndk)
) )
subscription.on('event', (ndkEvent) => { subscription.on('event', (ndkEvent) => {