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
const handler = (data: Event) => {
const customEvent = data as CustomEvent<NostrEvent>
const evt = customEvent.detail
const customEvent = data as CustomEvent<{ event: NostrEvent; relays: string[] }>
const { event } = customEvent.detail
if (
matchFilter(
{
kinds: filterKinds,
'#p': [pubkey]
},
evt
event
)
) {
handleNewEvent(evt)
handleNewEvent(event)
}
}

View file

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

View file

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