From 7ee258fe87f3d6eb4deb4a2aeb475d93469acce3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 25 Apr 2024 18:46:34 -0500 Subject: [PATCH] relay: fix local filtering logic --- src/controllers/nostr/relay.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/controllers/nostr/relay.ts b/src/controllers/nostr/relay.ts index 1fa53c1..30d7316 100644 --- a/src/controllers/nostr/relay.ts +++ b/src/controllers/nostr/relay.ts @@ -14,6 +14,7 @@ import { import { Storages } from '@/storages.ts'; import type { AppController } from '@/app.ts'; +import { Conf } from '@/config.ts'; /** Limit of initial events returned for a subscription. */ const FILTER_LIMIT = 100; @@ -129,11 +130,12 @@ function connectStream(socket: WebSocket) { /** Enforce the filters with certain criteria. */ function prepareFilters(filters: ClientREQ[2][]): NostrFilter[] { - return filters.map((filter) => ({ - ...filter, + return filters.map((filter) => { + const narrow = Boolean(filter.ids?.length || filter.authors?.length); + const search = narrow ? filter.search : `domain:${Conf.url.host} ${filter.search ?? ''}`; // Return only local events unless the query is already narrow. - local: (filter.ids?.length || filter.authors?.length) ? undefined : true, - })); + return { ...filter, search }; + }); } const relayController: AppController = (c, next) => {