comment fetching in mod posts fix #102
@ -1,14 +1,11 @@
|
||||
import {
|
||||
getRelayListForUser,
|
||||
NDKFilter,
|
||||
NDKKind,
|
||||
NDKRelaySet,
|
||||
NDKSubscription,
|
||||
NDKSubscriptionCacheUsage
|
||||
} from '@nostr-dev-kit/ndk'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { CommentEvent, ModDetails, UserRelaysType } from 'types'
|
||||
import { log, LogType } from 'utils'
|
||||
import { CommentEvent, ModDetails } from 'types'
|
||||
import { useNDKContext } from './useNDKContext'
|
||||
|
||||
export const useComments = (mod: ModDetails) => {
|
||||
@ -19,35 +16,18 @@ export const useComments = (mod: ModDetails) => {
|
||||
let subscription: NDKSubscription // Define the subscription variable here for cleanup
|
||||
|
||||
const setupSubscription = async () => {
|
||||
// Find the mod author's relays.
|
||||
const authorReadRelays = await getRelayListForUser(mod.author, ndk)
|
||||
.then((ndkRelayList) => {
|
||||
if (ndkRelayList) return ndkRelayList[UserRelaysType.Read]
|
||||
return [] // Return an empty array if ndkRelayList is undefined
|
||||
})
|
||||
.catch((err) => {
|
||||
log(
|
||||
true,
|
||||
LogType.Error,
|
||||
`An error occurred in fetching user's (${mod.author}) ${UserRelaysType.Read}`,
|
||||
err
|
||||
)
|
||||
return [] as string[]
|
||||
})
|
||||
|
||||
const filter: NDKFilter = {
|
||||
kinds: [NDKKind.Text],
|
||||
'#a': [mod.aTag]
|
||||
'#a': [mod.aTag],
|
||||
'#p': [mod.author]
|
||||
}
|
||||
|
||||
subscription = ndk.subscribe(
|
||||
filter,
|
||||
{
|
||||
closeOnEose: false,
|
||||
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST
|
||||
},
|
||||
NDKRelaySet.fromRelayUrls(authorReadRelays, ndk, true)
|
||||
)
|
||||
subscription = ndk.subscribe(filter, {
|
||||
closeOnEose: false,
|
||||
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST
|
||||
})
|
||||
|
||||
console.log('ndk.pool.urls() :>> ', ndk.pool.urls())
|
||||
|
||||
subscription.on('event', (ndkEvent) => {
|
||||
setCommentEvents((prev) => {
|
||||
|
Loading…
Reference in New Issue
Block a user