fix: 🐛

This commit is contained in:
codytseng 2025-12-29 23:14:06 +08:00
parent 6dc662bd2b
commit eb6c017319
3 changed files with 17 additions and 12 deletions

View file

@ -166,18 +166,18 @@ const NotificationList = forwardRef((_, ref) => {
if (!active || !pubkey) return if (!active || !pubkey) return
const handler = (data: Event) => { const handler = (data: Event) => {
const customEvent = data as CustomEvent<NostrEvent> const customEvent = data as CustomEvent<{ event: NostrEvent; relays: string[] }>
const evt = customEvent.detail const { event } = customEvent.detail
if ( if (
matchFilter( matchFilter(
{ {
kinds: filterKinds, kinds: filterKinds,
'#p': [pubkey] '#p': [pubkey]
}, },
evt event
) )
) { ) {
handleNewEvent(evt) handleNewEvent(event)
} }
} }

View file

@ -98,8 +98,9 @@ export function NotificationProvider({ children }: { children: React.ReactNode }
try { try {
let eosed = false let eosed = false
const relayList = await client.fetchRelayList(pubkey) const relayList = await client.fetchRelayList(pubkey)
const relays = relayList.read.length > 0 ? relayList.read.slice(0, 5) : BIG_RELAY_URLS
const subCloser = client.subscribe( const subCloser = client.subscribe(
relayList.read.length > 0 ? relayList.read.slice(0, 5) : BIG_RELAY_URLS, relays,
[ [
{ {
kinds: [ kinds: [
@ -135,7 +136,7 @@ export function NotificationProvider({ children }: { children: React.ReactNode }
return prev return prev
} }
client.emitNewEvent(evt) client.emitNewEvent(evt, relays)
return [evt, ...prev] return [evt, ...prev]
}) })
} }

View file

@ -178,7 +178,7 @@ class ClientService extends EventTarget {
const checkCompletion = () => { const checkCompletion = () => {
if (successCount >= successThreshold) { if (successCount >= successThreshold) {
this.emitNewEvent(event) this.emitNewEvent(event, uniqueRelayUrls)
resolve() resolve()
} }
if (++finishedCount >= uniqueRelayUrls.length) { if (++finishedCount >= uniqueRelayUrls.length) {
@ -240,8 +240,8 @@ class ClientService extends EventTarget {
}) })
} }
emitNewEvent(event: NEvent) { emitNewEvent(event: NEvent, relays: string[] = []) {
this.dispatchEvent(new CustomEvent('newEvent', { detail: event })) this.dispatchEvent(new CustomEvent('newEvent', { detail: { event, relays } }))
} }
async signHttpAuth(url: string, method: string, description = '') { async signHttpAuth(url: string, method: string, description = '') {
@ -531,9 +531,13 @@ class ClientService extends EventTarget {
}) })
const handleNewEventFromInternal = (data: Event) => { const handleNewEventFromInternal = (data: Event) => {
const customEvent = data as CustomEvent<NEvent> const customEvent = data as CustomEvent<{ event: NEvent; relays: string[] }>
const evt = customEvent.detail const { event: evt, relays: _relays } = customEvent.detail
if (!matchFilters(filters, evt)) return if (!_relays.some((url) => relays.includes(url))) {
return
}
const _filters = filters.filter((f) => !f.search)
if (_filters.length === 0 || !matchFilters(_filters, evt)) return
const id = evt.id const id = evt.id
const have = _knownIds.has(id) const have = _knownIds.has(id)