EventsDB: allow searching by domain

This commit is contained in:
Alex Gleason 2024-03-19 22:50:47 -05:00
parent 245cb43771
commit d17d4c846f
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 19 additions and 10 deletions

View File

@ -193,19 +193,28 @@ class EventsDB implements NStore {
}
}
if (typeof filter.local === 'boolean') {
query = query
.leftJoin(() => this.usersQuery(), (join) => join.onRef('users.d_tag', '=', 'events.pubkey'))
.where('users.d_tag', filter.local ? 'is not' : 'is', null);
}
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(q));
const domain = (tokens.find((t) =>
typeof t === 'object' && t.key === 'domain'
) as { key: 'domain'; value: string } | undefined)?.value;
if (domain) {
query = query
.innerJoin('pubkey_domains', 'pubkey_domains.pubkey', 'events.pubkey')
.where('pubkey_domains.domain', '=', domain);
}
const q = tokens.filter((t) =>
typeof t === 'string'
).join(' ');
if (q) {
query = query
.innerJoin('events_fts', 'events_fts.id', 'events.id')
.where('events_fts.content', 'match', JSON.stringify(q));
}
}
return query;