mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
EventsDB: allow searching by domain
This commit is contained in:
parent
245cb43771
commit
d17d4c846f
1 changed files with 19 additions and 10 deletions
|
|
@ -193,20 +193,29 @@ 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(' ');
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue