Move with_authors to GetFilterOpts instead of DittoFilter
This commit is contained in:
parent
f9d3240fa8
commit
e3d5b2ac4a
|
@ -144,31 +144,6 @@ function getFilterQuery(filter: DittoFilter): EventQuery {
|
|||
: query.leftJoin('users', 'users.pubkey', 'events.pubkey').where('users.pubkey', 'is', null) as typeof query;
|
||||
}
|
||||
|
||||
if (filter.with_authors) {
|
||||
// get kind 0 event associated with the `pubkey` field of the event
|
||||
query = query
|
||||
.leftJoin(
|
||||
(eb) =>
|
||||
eb
|
||||
.selectFrom('events')
|
||||
.selectAll()
|
||||
.where('kind', '=', 0)
|
||||
.orderBy('created_at', 'desc')
|
||||
.groupBy('pubkey')
|
||||
.as('authors'),
|
||||
(join) => join.onRef('authors.pubkey', '=', 'events.pubkey'),
|
||||
)
|
||||
.select([
|
||||
'authors.id as author_id',
|
||||
'authors.kind as author_kind',
|
||||
'authors.pubkey as author_pubkey',
|
||||
'authors.content as author_content',
|
||||
'authors.tags as author_tags',
|
||||
'authors.created_at as author_created_at',
|
||||
'authors.sig as author_sig',
|
||||
]);
|
||||
}
|
||||
|
||||
if (filter.search) {
|
||||
query = query
|
||||
.innerJoin('events_fts', 'events_fts.id', 'events.id')
|
||||
|
@ -197,6 +172,30 @@ async function getFilters<K extends number>(
|
|||
if (!filters.length) return Promise.resolve([]);
|
||||
let query = getFiltersQuery(filters);
|
||||
|
||||
if (opts.with_authors) {
|
||||
query = query
|
||||
.leftJoin(
|
||||
(eb) =>
|
||||
eb
|
||||
.selectFrom('events')
|
||||
.selectAll()
|
||||
.where('kind', '=', 0)
|
||||
.orderBy('created_at', 'desc')
|
||||
.groupBy('pubkey')
|
||||
.as('authors'),
|
||||
(join) => join.onRef('authors.pubkey', '=', 'events.pubkey'),
|
||||
)
|
||||
.select([
|
||||
'authors.id as author_id',
|
||||
'authors.kind as author_kind',
|
||||
'authors.pubkey as author_pubkey',
|
||||
'authors.content as author_content',
|
||||
'authors.tags as author_tags',
|
||||
'authors.created_at as author_created_at',
|
||||
'authors.sig as author_sig',
|
||||
]) as typeof query;
|
||||
}
|
||||
|
||||
if (typeof opts.limit === 'number') {
|
||||
query = query.limit(opts.limit);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import type { EventData } from '@/types.ts';
|
|||
/** Custom filter interface that extends Nostr filters with extra options for Ditto. */
|
||||
interface DittoFilter<K extends number = number> extends Filter<K> {
|
||||
local?: boolean;
|
||||
with_authors?: boolean;
|
||||
}
|
||||
|
||||
/** Additional options to apply to the whole subscription. */
|
||||
|
@ -15,6 +14,8 @@ interface GetFiltersOpts {
|
|||
timeout?: number;
|
||||
/** Event limit for the whole subscription. */
|
||||
limit?: number;
|
||||
/** Whether to include a corresponding kind 0 event in the `authors` key of each event. */
|
||||
with_authors?: boolean;
|
||||
}
|
||||
|
||||
function matchDittoFilter(filter: DittoFilter, event: Event, data: EventData): boolean {
|
||||
|
|
Loading…
Reference in New Issue