fix: 🐛
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { COMMENT_EVENT_KIND, PICTURE_EVENT_KIND } from '@/constants'
|
||||
import { BIG_RELAY_URLS, COMMENT_EVENT_KIND, PICTURE_EVENT_KIND } from '@/constants'
|
||||
import { useFetchEvent } from '@/hooks'
|
||||
import { extractEmbeddedNotesFromContent, extractImagesFromContent } from '@/lib/event'
|
||||
import { toNote } from '@/lib/link'
|
||||
@@ -63,7 +63,7 @@ const NotificationList = forwardRef((_, ref) => {
|
||||
const { closer, timelineKey } = await client.subscribeTimeline(
|
||||
relayList.read.length >= 4
|
||||
? relayList.read
|
||||
: relayList.read.concat(client.getDefaultRelayUrls()).slice(0, 4),
|
||||
: relayList.read.concat(BIG_RELAY_URLS).slice(0, 4),
|
||||
{
|
||||
'#p': [pubkey],
|
||||
kinds: [kinds.ShortTextNote, kinds.Repost, kinds.Reaction, COMMENT_EVENT_KIND],
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { getProfileFromProfileEvent } from '@/lib/event'
|
||||
import { userIdToPubkey } from '@/lib/pubkey'
|
||||
import { useNostr } from '@/providers/NostrProvider'
|
||||
import client from '@/services/client.service'
|
||||
import indexedDb from '@/services/indexed-db.service'
|
||||
import { TProfile } from '@/types'
|
||||
import { kinds } from 'nostr-tools'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
export function useFetchProfile(id?: string) {
|
||||
@@ -28,14 +25,6 @@ export function useFetchProfile(id?: string) {
|
||||
|
||||
const pubkey = userIdToPubkey(id)
|
||||
setPubkey(pubkey)
|
||||
const storedProfileEvent = await indexedDb.getReplaceableEvent(pubkey, kinds.Metadata)
|
||||
if (storedProfileEvent) {
|
||||
const profile = getProfileFromProfileEvent(storedProfileEvent)
|
||||
setProfile(profile)
|
||||
setIsFetching(false)
|
||||
return
|
||||
}
|
||||
|
||||
const profile = await client.fetchProfile(id)
|
||||
if (profile) {
|
||||
setProfile(profile)
|
||||
@@ -54,7 +43,7 @@ export function useFetchProfile(id?: string) {
|
||||
if (currentAccountProfile && pubkey === currentAccountProfile.pubkey) {
|
||||
setProfile(currentAccountProfile)
|
||||
}
|
||||
}, [currentAccountProfile])
|
||||
}, [currentAccountProfile, pubkey])
|
||||
|
||||
return { isFetching, error, profile }
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { BIG_RELAY_URLS } from '@/constants'
|
||||
import { createMuteListDraftEvent } from '@/lib/draft-event'
|
||||
import { getLatestEvent } from '@/lib/event'
|
||||
import { extractPubkeysFromEventTags, isSameTag } from '@/lib/tag'
|
||||
@@ -41,7 +42,7 @@ export function MuteListProvider({ children }: { children: React.ReactNode }) {
|
||||
const tags = await extractMuteTags(storedMuteListEvent)
|
||||
setTags(tags)
|
||||
}
|
||||
const events = await client.fetchEvents(relayList?.write ?? client.getDefaultRelayUrls(), {
|
||||
const events = await client.fetchEvents(relayList?.write ?? BIG_RELAY_URLS, {
|
||||
kinds: [kinds.Mutelist],
|
||||
authors: [accountPubkey]
|
||||
})
|
||||
|
||||
@@ -360,7 +360,8 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
||||
? specifiedRelayUrls
|
||||
: (relayList?.write ?? [])
|
||||
.concat(additionalRelayUrls ?? [])
|
||||
.concat(client.getDefaultRelayUrls()),
|
||||
.concat(client.getCurrentRelayUrls())
|
||||
.concat(BIG_RELAY_URLS),
|
||||
event
|
||||
)
|
||||
return event
|
||||
|
||||
@@ -26,7 +26,7 @@ class ClientService extends EventTarget {
|
||||
static instance: ClientService
|
||||
|
||||
signer?: (evt: TDraftEvent) => Promise<VerifiedEvent>
|
||||
private defaultRelayUrls: string[] = BIG_RELAY_URLS
|
||||
private currentRelayUrls: string[] = []
|
||||
private pool: SimplePool
|
||||
|
||||
private timelines: Record<
|
||||
@@ -43,7 +43,7 @@ class ClientService extends EventTarget {
|
||||
(ids) => Promise.all(ids.map((id) => this._fetchEvent(id))),
|
||||
{ cacheMap: this.eventCache }
|
||||
)
|
||||
private fetchEventFromDefaultRelaysDataloader = new DataLoader<string, NEvent | undefined>(
|
||||
private fetchEventFromBigRelaysDataloader = new DataLoader<string, NEvent | undefined>(
|
||||
this.eventBatchLoadFn.bind(this),
|
||||
{ cache: false }
|
||||
)
|
||||
@@ -54,7 +54,7 @@ class ClientService extends EventTarget {
|
||||
maxBatchSize: 50
|
||||
}
|
||||
)
|
||||
private fetchProfileEventFromDefaultRelaysDataloader = new DataLoader<string, NEvent | undefined>(
|
||||
private fetchProfileEventFromBigRelaysDataloader = new DataLoader<string, NEvent | undefined>(
|
||||
this.profileEventBatchLoadFn.bind(this),
|
||||
{
|
||||
cacheMap: new LRUCache<string, Promise<NEvent | undefined>>({ max: 1000 }),
|
||||
@@ -100,11 +100,11 @@ class ClientService extends EventTarget {
|
||||
}
|
||||
|
||||
setCurrentRelayUrls(urls: string[]) {
|
||||
this.defaultRelayUrls = Array.from(new Set(urls.concat(BIG_RELAY_URLS)))
|
||||
this.currentRelayUrls = urls
|
||||
}
|
||||
|
||||
getDefaultRelayUrls() {
|
||||
return this.defaultRelayUrls
|
||||
getCurrentRelayUrls() {
|
||||
return this.currentRelayUrls
|
||||
}
|
||||
|
||||
async publishEvent(relayUrls: string[], event: NEvent) {
|
||||
@@ -422,7 +422,7 @@ class ClientService extends EventTarget {
|
||||
|
||||
async fetchEvents(relayUrls: string[], filter: Filter, cache = false) {
|
||||
const events = await this.query(
|
||||
relayUrls.length > 0 ? relayUrls : this.defaultRelayUrls,
|
||||
relayUrls.length > 0 ? relayUrls : this.currentRelayUrls.concat(BIG_RELAY_URLS),
|
||||
filter
|
||||
)
|
||||
if (cache) {
|
||||
@@ -622,7 +622,7 @@ class ClientService extends EventTarget {
|
||||
}
|
||||
|
||||
private async fetchEventById(relayUrls: string[], id: string): Promise<NEvent | undefined> {
|
||||
const event = await this.fetchEventFromDefaultRelaysDataloader.load(id)
|
||||
const event = await this.fetchEventFromBigRelaysDataloader.load(id)
|
||||
if (event) {
|
||||
return event
|
||||
}
|
||||
@@ -703,12 +703,11 @@ class ClientService extends EventTarget {
|
||||
this.addUsernameToIndex(localProfile)
|
||||
return localProfile
|
||||
}
|
||||
const profileFromDefaultRelays =
|
||||
await this.fetchProfileEventFromDefaultRelaysDataloader.load(pubkey)
|
||||
if (profileFromDefaultRelays) {
|
||||
this.addUsernameToIndex(profileFromDefaultRelays)
|
||||
await indexedDb.putReplaceableEvent(profileFromDefaultRelays)
|
||||
return profileFromDefaultRelays
|
||||
const profileFromBigRelays = await this.fetchProfileEventFromBigRelaysDataloader.load(pubkey)
|
||||
if (profileFromBigRelays) {
|
||||
this.addUsernameToIndex(profileFromBigRelays)
|
||||
await indexedDb.putReplaceableEvent(profileFromBigRelays)
|
||||
return profileFromBigRelays
|
||||
}
|
||||
|
||||
const profileEvent = await this.tryHarderToFetchEvent(
|
||||
@@ -756,15 +755,15 @@ class ClientService extends EventTarget {
|
||||
private async tryHarderToFetchEvent(
|
||||
relayUrls: string[],
|
||||
filter: Filter,
|
||||
alreadyFetchedFromDefaultRelays = false
|
||||
alreadyFetchedFromBigRelays = false
|
||||
) {
|
||||
if (!relayUrls.length && filter.authors?.length) {
|
||||
const relayList = await this.fetchRelayList(filter.authors[0])
|
||||
relayUrls = alreadyFetchedFromDefaultRelays
|
||||
? relayList.write.filter((url) => !this.defaultRelayUrls.includes(url)).slice(0, 4)
|
||||
relayUrls = alreadyFetchedFromBigRelays
|
||||
? relayList.write.filter((url) => !BIG_RELAY_URLS.includes(url)).slice(0, 4)
|
||||
: relayList.write.slice(0, 4)
|
||||
} else if (!relayUrls.length && !alreadyFetchedFromDefaultRelays) {
|
||||
relayUrls = this.defaultRelayUrls
|
||||
} else if (!relayUrls.length && !alreadyFetchedFromBigRelays) {
|
||||
relayUrls = BIG_RELAY_URLS
|
||||
}
|
||||
if (!relayUrls.length) return
|
||||
|
||||
@@ -773,7 +772,7 @@ class ClientService extends EventTarget {
|
||||
}
|
||||
|
||||
private async eventBatchLoadFn(ids: readonly string[]) {
|
||||
const events = await this.query(this.defaultRelayUrls, {
|
||||
const events = await this.query(BIG_RELAY_URLS, {
|
||||
ids: Array.from(new Set(ids)),
|
||||
limit: ids.length
|
||||
})
|
||||
@@ -786,7 +785,7 @@ class ClientService extends EventTarget {
|
||||
}
|
||||
|
||||
private async profileEventBatchLoadFn(pubkeys: readonly string[]) {
|
||||
const events = await this.query(this.defaultRelayUrls, {
|
||||
const events = await this.query(BIG_RELAY_URLS, {
|
||||
authors: Array.from(new Set(pubkeys)),
|
||||
kinds: [kinds.Metadata],
|
||||
limit: pubkeys.length
|
||||
@@ -817,7 +816,7 @@ class ClientService extends EventTarget {
|
||||
)
|
||||
const nonExistingPubkeys = pubkeys.filter((_, i) => !relayEvents[i])
|
||||
if (nonExistingPubkeys.length) {
|
||||
const events = await this.query(this.defaultRelayUrls, {
|
||||
const events = await this.query(BIG_RELAY_URLS, {
|
||||
authors: pubkeys as string[],
|
||||
kinds: [kinds.RelayList],
|
||||
limit: pubkeys.length
|
||||
@@ -847,7 +846,7 @@ class ClientService extends EventTarget {
|
||||
|
||||
private async _fetchFollowListEvent(pubkey: string) {
|
||||
const relayList = await this.fetchRelayList(pubkey)
|
||||
const followListEvents = await this.query(relayList.write.concat(this.defaultRelayUrls), {
|
||||
const followListEvents = await this.query(relayList.write.concat(BIG_RELAY_URLS), {
|
||||
authors: [pubkey],
|
||||
kinds: [kinds.Contacts]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user