Pool: Sub use provided alreadyHaveEvent Fn

This commit is contained in:
BilligsterUser 2023-03-06 17:16:16 +01:00 committed by fiatjaf_
parent 73decbc8e0
commit 5539e5cf89
1 changed files with 4 additions and 3 deletions

View File

@ -30,7 +30,7 @@ export class SimplePool {
if (existing && existing.status === 1) return existing
if (existing) {
await existing.connect();
await existing.connect()
return existing
}
@ -47,8 +47,9 @@ export class SimplePool {
sub(relays: string[], filters: Filter[], opts?: SubscriptionOptions): Sub {
let _knownIds: Set<string> = new Set()
let modifiedOpts = opts || {}
modifiedOpts.alreadyHaveEvent = (id, url) => {
let modifiedOpts = {...opts || {}}
modifiedOpts.alreadyHaveEvent = (id, url) => {
if (opts?.alreadyHaveEvent?.(id, url)) { return true }
let set = this._seenOn[id] || new Set()
set.add(url)
this._seenOn[id] = set