From 3a2facd899ddb2af1b1d766592c44c1383b1381f Mon Sep 17 00:00:00 2001 From: Martti Malmi Date: Fri, 5 Jan 2024 14:01:34 +0200 Subject: [PATCH] send not filter to relays that support nip-113 --- packages/system/src/nips.ts | 1 + packages/system/src/nostr-system.ts | 11 +++++------ packages/system/src/query.ts | 10 ++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/system/src/nips.ts b/packages/system/src/nips.ts index decdfa3c..72c15921 100644 --- a/packages/system/src/nips.ts +++ b/packages/system/src/nips.ts @@ -1,3 +1,4 @@ export enum Nips { Search = 50, + NotFilter = 113, } diff --git a/packages/system/src/nostr-system.ts b/packages/system/src/nostr-system.ts index 1da547aa..3e819acc 100644 --- a/packages/system/src/nostr-system.ts +++ b/packages/system/src/nostr-system.ts @@ -324,16 +324,15 @@ export class NostrSystem extends EventEmitter implements Syst this.HandleEvent(e); return e.id; }); - let fCopy = { ...f }; // some relays reject the query if it contains an unknown key. only send locally. if (alreadyHave.length) { - fCopy.not = fCopy.not ?? {}; - if (fCopy.not.ids) { - fCopy.not.ids.push(...alreadyHave); + f.not = f.not ?? {}; + if (f.not.ids) { + f.not.ids.push(...alreadyHave); } else { - fCopy.not.ids = alreadyHave; + f.not.ids = alreadyHave; } } - this.emit("request", fCopy); + this.emit("request", f); }); if (qSend.relay) { diff --git a/packages/system/src/query.ts b/packages/system/src/query.ts index 68e54e08..50213462 100644 --- a/packages/system/src/query.ts +++ b/packages/system/src/query.ts @@ -321,6 +321,16 @@ export class Query extends EventEmitter implements QueryBase { } #sendQueryInternal(c: Connection, q: BuiltRawReqFilter) { + if (!c.SupportsNip(Nips.NotFilter)) { + q.filters = q.filters.map(f => { + if (f.not) { + const copy = { ...f }; + delete copy.not; + return copy; + } + return f; + }); + } const qt = new QueryTrace(c.Address, q.filters, c.Id); qt.on("close", x => c.CloseReq(x)); qt.on("change", () => this.#onProgress());