Make DVMs work better
This commit is contained in:
@@ -6,6 +6,7 @@ import {makeDvmRequest} from '@welshman/dvm'
|
||||
import {makeSecret, Nip01Signer} from '@welshman/signer'
|
||||
import {pubkey, signer} from './session'
|
||||
import {getFilterSelections} from './router'
|
||||
import {loadRelaySelections} from './relaySelections'
|
||||
import {wotGraph, maxWot, getFollows, getNetwork, getFollowers} from './wot'
|
||||
import {load} from './core'
|
||||
|
||||
@@ -21,7 +22,14 @@ export const request = async ({filters = [{}], relays = [], onEvent}: RequestOpt
|
||||
}
|
||||
|
||||
export const requestDVM = async ({kind, onEvent, ...request}: DVMOpts) => {
|
||||
const tags = [...request.tags || [], ["expiration", String(now() + 5)]]
|
||||
// Make sure we know what relays to use for target dvms
|
||||
if (request.tags && !request.relays) {
|
||||
for (const pubkey of getPubkeyTagValues(request.tags)) {
|
||||
await loadRelaySelections(pubkey)
|
||||
}
|
||||
}
|
||||
|
||||
const tags = [...request.tags || [], ["expiration", String(now() + 60)]]
|
||||
const $signer = signer.get() || new Nip01Signer(makeSecret())
|
||||
const event = await $signer.sign(createEvent(kind, {tags}))
|
||||
const relays =
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {Emitter, now} from '@welshman/lib'
|
||||
import type {TrustedEvent, SignedEvent} from '@welshman/util'
|
||||
import {subscribe, publish} from '@welshman/net'
|
||||
import type {TrustedEvent, SignedEvent, Filter} from '@welshman/util'
|
||||
import {getPubkeyTagValues} from '@welshman/util'
|
||||
import {subscribe, publish, SubscriptionEvent} from '@welshman/net'
|
||||
import type {Subscription, Publish} from '@welshman/net'
|
||||
|
||||
export enum DVMEvent {
|
||||
@@ -28,11 +29,19 @@ export const makeDvmRequest = (request: DVMRequestOptions) => {
|
||||
const {event, relays, timeout = 30_000, autoClose = true, reportProgress = true} = request
|
||||
const kind = event.kind + 1000
|
||||
const kinds = reportProgress ? [kind, 7000] : [kind]
|
||||
const filters = [{kinds, since: now() - 60, "#e": [event.id]}]
|
||||
|
||||
// DVMs seem to no longer be responding to requests, but lots of events exist for their
|
||||
// pubkeys. So query both, at least until people figure out how dvms are supposed to work
|
||||
const filters: Filter[] = [
|
||||
{kinds, authors: getPubkeyTagValues(event.tags)},
|
||||
{kinds, since: now() - 60, "#e": [event.id]},
|
||||
]
|
||||
|
||||
const sub = subscribe({relays, timeout, filters})
|
||||
const pub = publish({event, relays, timeout})
|
||||
|
||||
sub.emitter.on('event', (url: string, event: TrustedEvent) => {
|
||||
|
||||
sub.emitter.on(SubscriptionEvent.Event, (url: string, event: TrustedEvent) => {
|
||||
if (event.kind === 7000) {
|
||||
emitter.emit(DVMEvent.Progress, url, event)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user