make pool.publish() return a single Pub object.

This commit is contained in:
fiatjaf
2023-02-26 17:44:51 -03:00
parent a8938a3a0f
commit c362212778
2 changed files with 15 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "nostr-tools", "name": "nostr-tools",
"version": "1.6.3", "version": "1.7.0",
"description": "Tools for making a Nostr client.", "description": "Tools for making a Nostr client.",
"repository": { "repository": {
"type": "git", "type": "git",

18
pool.ts
View File

@@ -155,13 +155,23 @@ export class SimplePool {
}) })
} }
publish(relays: string[], event: Event): Pub[] { publish(relays: string[], event: Event): Pub {
return relays.map(relay => { let pubs = relays.map(relay => {
let r = this._conn[normalizeURL(relay)] let r = this._conn[normalizeURL(relay)]
if (!r) return badPub(relay) if (!r) return badPub(relay)
let s = r.publish(event) return r.publish(event)
return s
}) })
return {
on(type, cb) {
pubs.forEach((pub, i) => {
pub.on(type, () => cb(relays[i]))
})
},
off() {
// do nothing here, FIXME
}
}
} }
seenOn(id: string): string[] { seenOn(id: string): string[] {