db/events: fix the `local` filter

This commit is contained in:
Alex Gleason 2023-12-29 20:53:01 -06:00
parent 358396fdac
commit 9492b7654f
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 12 additions and 3 deletions

View File

@ -154,11 +154,11 @@ function getFilterQuery(filter: DittoFilter): EventQuery {
}
}
// FIXME: local filtering is broken.
if (typeof filter.local === 'boolean') {
query = filter.local
? query.innerJoin('users', 'users.pubkey', 'events.pubkey') as typeof query
: query.leftJoin('users', 'users.pubkey', 'events.pubkey').where('users.pubkey', 'is', null) as typeof query;
? query.innerJoin(usersQuery, (join) => join.onRef('users.d_tag', '=', 'events.pubkey'))
: query.leftJoin(usersQuery, (join) => join.onRef('users.d_tag', '=', 'events.pubkey'))
.where('users.d_tag', 'is', null);
}
if (filter.relations?.includes('author')) {
@ -220,6 +220,15 @@ function getEventsQuery(filters: DittoFilter[]) {
.reduce((result, query) => result.unionAll(query));
}
/** Query to get user events, joined by tags. */
function usersQuery() {
return getFilterQuery({ kinds: [30361], authors: [Conf.pubkey] })
.leftJoin('tags', 'tags.event_id', 'events.id')
.where('tags.tag', '=', 'd')
.select('tags.value as d_tag')
.as('users');
}
/** Get events for filters from the database. */
async function getEvents<K extends number>(
filters: DittoFilter<K>[],