mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
Pool: Sub use provided alreadyHaveEvent Fn
This commit is contained in:
7
pool.ts
7
pool.ts
@@ -30,7 +30,7 @@ export class SimplePool {
|
|||||||
if (existing && existing.status === 1) return existing
|
if (existing && existing.status === 1) return existing
|
||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
await existing.connect();
|
await existing.connect()
|
||||||
return existing
|
return existing
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,8 +47,9 @@ export class SimplePool {
|
|||||||
|
|
||||||
sub(relays: string[], filters: Filter[], opts?: SubscriptionOptions): Sub {
|
sub(relays: string[], filters: Filter[], opts?: SubscriptionOptions): Sub {
|
||||||
let _knownIds: Set<string> = new Set()
|
let _knownIds: Set<string> = new Set()
|
||||||
let modifiedOpts = opts || {}
|
let modifiedOpts = {...opts || {}}
|
||||||
modifiedOpts.alreadyHaveEvent = (id, url) => {
|
modifiedOpts.alreadyHaveEvent = (id, url) => {
|
||||||
|
if (opts?.alreadyHaveEvent?.(id, url)) { return true }
|
||||||
let set = this._seenOn[id] || new Set()
|
let set = this._seenOn[id] || new Set()
|
||||||
set.add(url)
|
set.add(url)
|
||||||
this._seenOn[id] = set
|
this._seenOn[id] = set
|
||||||
|
|||||||
Reference in New Issue
Block a user