EventsDB: parse nip50 extensions

This commit is contained in:
Alex Gleason 2024-03-19 22:46:54 -05:00
parent e2cc6132be
commit 245cb43771
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 6 additions and 2 deletions

View File

@ -10,7 +10,7 @@
"relays:sync": "deno run -A --unstable-ffi scripts/relays.ts sync" "relays:sync": "deno run -A --unstable-ffi scripts/relays.ts sync"
}, },
"exclude": ["./public"], "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": { "lint": {
"include": ["src/", "scripts/"], "include": ["src/", "scripts/"],
"rules": { "rules": {

View File

@ -1,3 +1,4 @@
import { NIP50 } from '@soapbox/nspec';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { type DittoDB } from '@/db.ts'; import { type DittoDB } from '@/db.ts';
import { Debug, Kysely, type NostrEvent, type NStore, type NStoreOpts, type SelectQueryBuilder } from '@/deps.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) { if (filter.search) {
const tokens = NIP50.parseInput(filter.search);
const q = tokens.filter((t) => typeof t === 'string').join(' ');
query = query query = query
.innerJoin('events_fts', 'events_fts.id', 'events.id') .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; return query;