Small tweaks to subscriptions
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import {ctx, isNil} from "@welshman/lib"
|
import {ctx, isNil} from "@welshman/lib"
|
||||||
import {Repository, Relay, LOCAL_RELAY_URL, getFilterResultCardinality} from "@welshman/util"
|
import {Repository, Relay, LOCAL_RELAY_URL, getFilterResultCardinality} from "@welshman/util"
|
||||||
import type {TrustedEvent, Filter} from "@welshman/util"
|
import type {TrustedEvent, Filter} from "@welshman/util"
|
||||||
import {Tracker, subscribe as baseSubscribe} from "@welshman/net"
|
import {Tracker, subscribe as baseSubscribe, SubscriptionEvent} from "@welshman/net"
|
||||||
import type {SubscribeRequestWithHandlers} from "@welshman/net"
|
import type {SubscribeRequestWithHandlers} from "@welshman/net"
|
||||||
import {custom} from "@welshman/store"
|
import {custom} from "@welshman/store"
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ export const subscribe = (request: PartialSubscribeRequest) => {
|
|||||||
// Keep cached results async so the caller can set up handlers
|
// Keep cached results async so the caller can set up handlers
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
sub.emitter.emit("event", LOCAL_RELAY_URL, event)
|
sub.emitter.emit(SubscriptionEvent.Event, LOCAL_RELAY_URL, event)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -80,6 +80,6 @@ export const load = (request: PartialSubscribeRequest) =>
|
|||||||
const sub = subscribe({closeOnEose: true, timeout: ctx.app.requestTimeout, ...request})
|
const sub = subscribe({closeOnEose: true, timeout: ctx.app.requestTimeout, ...request})
|
||||||
const events: TrustedEvent[] = []
|
const events: TrustedEvent[] = []
|
||||||
|
|
||||||
sub.emitter.on("event", (url: string, e: TrustedEvent) => events.push(e))
|
sub.emitter.on(SubscriptionEvent.Event, (url: string, e: TrustedEvent) => events.push(e))
|
||||||
sub.emitter.on("complete", () => resolve(events))
|
sub.emitter.on(SubscriptionEvent.Complete, () => resolve(events))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -223,14 +223,9 @@ const _executeSubscription = (sub: Subscription) => {
|
|||||||
const executor = ctx.net.getExecutor(relays)
|
const executor = ctx.net.getExecutor(relays)
|
||||||
const subs: {unsubscribe: () => void}[] = []
|
const subs: {unsubscribe: () => void}[] = []
|
||||||
const completedRelays = new Set()
|
const completedRelays = new Set()
|
||||||
const events: TrustedEvent[] = []
|
|
||||||
|
|
||||||
// Hook up our events
|
// Hook up our events
|
||||||
|
|
||||||
emitter.on(SubscriptionEvent.Event, (url: string, event: TrustedEvent) => {
|
|
||||||
events.push(event)
|
|
||||||
})
|
|
||||||
|
|
||||||
emitter.on(SubscriptionEvent.Eose, (url: string) => {
|
emitter.on(SubscriptionEvent.Eose, (url: string) => {
|
||||||
completedRelays.add(url)
|
completedRelays.add(url)
|
||||||
|
|
||||||
|
|||||||
@@ -196,16 +196,16 @@ export class Nip46Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (response.result === "auth_url") {
|
if (response.result === "auth_url") {
|
||||||
return popupManager.open(response.error!)
|
popupManager.open(response.error!)
|
||||||
}
|
|
||||||
|
|
||||||
if (response.error) {
|
|
||||||
this.promise.reject(response as Nip46ResponseWithError)
|
|
||||||
} else {
|
} else {
|
||||||
this.promise.resolve(response as Nip46ResponseWithResult)
|
if (response.error) {
|
||||||
}
|
this.promise.reject(response as Nip46ResponseWithError)
|
||||||
|
} else {
|
||||||
|
this.promise.resolve(response as Nip46ResponseWithResult)
|
||||||
|
}
|
||||||
|
|
||||||
receiver.off(Nip46Event.Receive, onReceive)
|
receiver.off(Nip46Event.Receive, onReceive)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
receiver.on(Nip46Event.Receive, onReceive)
|
receiver.on(Nip46Event.Receive, onReceive)
|
||||||
|
|||||||
Reference in New Issue
Block a user