db/events: fix `local: false` filter
This commit is contained in:
parent
8ec215402f
commit
08dd5fa4eb
|
@ -2,6 +2,7 @@ import event55920b75 from '~/fixtures/events/55920b75.json' assert { type: 'json
|
||||||
import { assertEquals } from '@/deps-test.ts';
|
import { assertEquals } from '@/deps-test.ts';
|
||||||
|
|
||||||
import { countFilters, deleteFilters, getFilters, insertEvent } from './events.ts';
|
import { countFilters, deleteFilters, getFilters, insertEvent } from './events.ts';
|
||||||
|
import { insertUser } from '@/db/users.ts';
|
||||||
|
|
||||||
Deno.test('count filters', async () => {
|
Deno.test('count filters', async () => {
|
||||||
assertEquals(await countFilters([{ kinds: [1] }]), 0);
|
assertEquals(await countFilters([{ kinds: [1] }]), 0);
|
||||||
|
@ -28,3 +29,21 @@ Deno.test('delete events', async () => {
|
||||||
await deleteFilters([{ kinds: [1] }]);
|
await deleteFilters([{ kinds: [1] }]);
|
||||||
assertEquals(await getFilters([{ kinds: [1] }]), []);
|
assertEquals(await getFilters([{ kinds: [1] }]), []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test('query events with local filter', async () => {
|
||||||
|
await insertEvent(event55920b75);
|
||||||
|
|
||||||
|
assertEquals(await getFilters([{}]), [event55920b75]);
|
||||||
|
assertEquals(await getFilters([{ local: true }]), []);
|
||||||
|
assertEquals(await getFilters([{ local: false }]), [event55920b75]);
|
||||||
|
|
||||||
|
await insertUser({
|
||||||
|
username: 'alex',
|
||||||
|
pubkey: event55920b75.pubkey,
|
||||||
|
inserted_at: new Date(),
|
||||||
|
admin: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
assertEquals(await getFilters([{ local: true }]), [event55920b75]);
|
||||||
|
assertEquals(await getFilters([{ local: false }]), []);
|
||||||
|
});
|
||||||
|
|
|
@ -115,8 +115,10 @@ function getFilterQuery(filter: DittoFilter) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.local) {
|
if (typeof filter.local === 'boolean') {
|
||||||
query = query.innerJoin('users', 'users.pubkey', 'events.pubkey');
|
query = filter.local
|
||||||
|
? query.innerJoin('users', 'users.pubkey', 'events.pubkey')
|
||||||
|
: query.leftJoin('users', 'users.pubkey', 'events.pubkey').where('users.pubkey', 'is', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.search) {
|
if (filter.search) {
|
||||||
|
|
Loading…
Reference in New Issue