Ensure .language property gets added to DittoEvent when it's queried

This commit is contained in:
Alex Gleason 2025-02-11 13:19:32 -06:00
parent 207e04ef08
commit 43d675b837
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -1,9 +1,10 @@
// deno-lint-ignore-file require-await
import { NPostgres } from '@nostrify/db';
import { NPostgres, NPostgresSchema } from '@nostrify/db';
import { NIP50, NKinds, NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
import { logi } from '@soapbox/logi';
import { JsonValue } from '@std/json';
import { LanguageCode } from 'iso-639-1';
import { Kysely } from 'kysely';
import { nip27 } from 'nostr-tools';
import { z } from 'zod';
@ -231,6 +232,25 @@ class EventsDB extends NPostgres {
return super.query(filters, { ...opts, timeout: opts.timeout ?? this.opts.timeout });
}
/** Parse an event row from the database. */
protected override parseEventRow(row: NPostgresSchema['nostr_events']): DittoEvent {
const event: DittoEvent = {
id: row.id,
kind: row.kind,
pubkey: row.pubkey,
content: row.content,
created_at: Number(row.created_at),
tags: row.tags,
sig: row.sig,
};
if (!this.opts.pure) {
event.language = row.search_ext.language as LanguageCode | undefined;
}
return event;
}
/** Delete events based on filters from the database. */
override async remove(filters: NostrFilter[], opts: { signal?: AbortSignal; timeout?: number } = {}): Promise<void> {
logi({ level: 'debug', ns: 'ditto.remove', source: 'db', filters: filters as JsonValue });