From 245cb43771d13f2e078562f06467862c224f6e45 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 19 Mar 2024 22:46:54 -0500 Subject: [PATCH] EventsDB: parse nip50 extensions --- deno.json | 2 +- src/storages/events-db.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/deno.json b/deno.json index ccb54ad..b5fe33b 100644 --- a/deno.json +++ b/deno.json @@ -10,7 +10,7 @@ "relays:sync": "deno run -A --unstable-ffi scripts/relays.ts sync" }, "exclude": ["./public"], - "imports": { "@/": "./src/", "@soapbox/nspec": "jsr:@soapbox/nspec@^0.7.0", "~/fixtures/": "./fixtures/" }, + "imports": { "@/": "./src/", "@soapbox/nspec": "jsr:@soapbox/nspec@^0.8.0", "~/fixtures/": "./fixtures/" }, "lint": { "include": ["src/", "scripts/"], "rules": { diff --git a/src/storages/events-db.ts b/src/storages/events-db.ts index 0253ef3..b77f309 100644 --- a/src/storages/events-db.ts +++ b/src/storages/events-db.ts @@ -1,3 +1,4 @@ +import { NIP50 } from '@soapbox/nspec'; import { Conf } from '@/config.ts'; import { type DittoDB } from '@/db.ts'; import { Debug, Kysely, type NostrEvent, type NStore, type NStoreOpts, type SelectQueryBuilder } from '@/deps.ts'; @@ -199,9 +200,12 @@ class EventsDB implements NStore { } if (filter.search) { + const tokens = NIP50.parseInput(filter.search); + const q = tokens.filter((t) => typeof t === 'string').join(' '); + query = query .innerJoin('events_fts', 'events_fts.id', 'events.id') - .where('events_fts.content', 'match', JSON.stringify(filter.search)); + .where('events_fts.content', 'match', JSON.stringify(q)); } return query;