mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
fix: fix language property in the Mastodon API
This commit is contained in:
parent
bbbce958d9
commit
4712cb1d80
3 changed files with 21 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import { NostrEvent } from '@nostrify/nostrify';
|
import { NostrEvent } from '@nostrify/nostrify';
|
||||||
|
import { LanguageCode } from 'iso-639-1';
|
||||||
|
|
||||||
/** Ditto internal stats for the event's author. */
|
/** Ditto internal stats for the event's author. */
|
||||||
export interface AuthorStats {
|
export interface AuthorStats {
|
||||||
|
|
@ -43,4 +44,6 @@ export interface DittoEvent extends NostrEvent {
|
||||||
zap_sender?: DittoEvent | string;
|
zap_sender?: DittoEvent | string;
|
||||||
zap_amount?: number;
|
zap_amount?: number;
|
||||||
zap_message?: string;
|
zap_message?: string;
|
||||||
|
/** Language of the event (kind 1s are more accurate). */
|
||||||
|
language?: LanguageCode;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
// deno-lint-ignore-file require-await
|
// deno-lint-ignore-file require-await
|
||||||
|
|
||||||
|
import { LanguageCode } from 'iso-639-1';
|
||||||
import { NPostgres, NPostgresSchema } from '@nostrify/db';
|
import { NPostgres, NPostgresSchema } from '@nostrify/db';
|
||||||
import { NIP50, NKinds, NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
import { NIP50, NKinds, NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
||||||
import { Stickynotes } from '@soapbox/stickynotes';
|
import { Stickynotes } from '@soapbox/stickynotes';
|
||||||
|
|
@ -12,6 +13,7 @@ import { RelayError } from '@/RelayError.ts';
|
||||||
import { isNostrId, isURL } from '@/utils.ts';
|
import { isNostrId, isURL } from '@/utils.ts';
|
||||||
import { abortError } from '@/utils/abort.ts';
|
import { abortError } from '@/utils/abort.ts';
|
||||||
import { purifyEvent } from '@/utils/purify.ts';
|
import { purifyEvent } from '@/utils/purify.ts';
|
||||||
|
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||||
|
|
||||||
/** Function to decide whether or not to index a tag. */
|
/** Function to decide whether or not to index a tag. */
|
||||||
type TagCondition = ({ event, count, value }: {
|
type TagCondition = ({ event, count, value }: {
|
||||||
|
|
@ -175,7 +177,7 @@ class EventsDB extends NPostgres {
|
||||||
override async query(
|
override async query(
|
||||||
filters: NostrFilter[],
|
filters: NostrFilter[],
|
||||||
opts: { signal?: AbortSignal; timeout?: number; limit?: number } = {},
|
opts: { signal?: AbortSignal; timeout?: number; limit?: number } = {},
|
||||||
): Promise<NostrEvent[]> {
|
): Promise<DittoEvent[]> {
|
||||||
filters = await this.expandFilters(filters);
|
filters = await this.expandFilters(filters);
|
||||||
|
|
||||||
for (const filter of filters) {
|
for (const filter of filters) {
|
||||||
|
|
@ -199,6 +201,20 @@ class EventsDB extends NPostgres {
|
||||||
return super.query(filters, { ...opts, timeout: opts.timeout ?? this.opts.timeout });
|
return super.query(filters, { ...opts, timeout: opts.timeout ?? this.opts.timeout });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Parse an event row from the database. */
|
||||||
|
protected override parseEventRow(row: Pick<DittoTables['nostr_events'], keyof NostrEvent | 'language'>): DittoEvent {
|
||||||
|
return {
|
||||||
|
id: row.id,
|
||||||
|
kind: row.kind,
|
||||||
|
pubkey: row.pubkey,
|
||||||
|
content: row.content,
|
||||||
|
created_at: Number(row.created_at),
|
||||||
|
tags: row.tags,
|
||||||
|
sig: row.sig,
|
||||||
|
language: (row.language || undefined) as LanguageCode,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/** Delete events based on filters from the database. */
|
/** Delete events based on filters from the database. */
|
||||||
override async remove(filters: NostrFilter[], opts: { signal?: AbortSignal; timeout?: number } = {}): Promise<void> {
|
override async remove(filters: NostrFilter[], opts: { signal?: AbortSignal; timeout?: number } = {}): Promise<void> {
|
||||||
this.console.debug('DELETE', JSON.stringify(filters));
|
this.console.debug('DELETE', JSON.stringify(filters));
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ async function renderStatus(event: DittoEvent, opts: RenderStatusOpts): Promise<
|
||||||
sensitive: !!cw,
|
sensitive: !!cw,
|
||||||
spoiler_text: (cw ? cw[1] : subject?.[1]) || '',
|
spoiler_text: (cw ? cw[1] : subject?.[1]) || '',
|
||||||
visibility: 'public',
|
visibility: 'public',
|
||||||
language: event.tags.find((tag) => tag[0] === 'l' && tag[2] === 'ISO-639-1')?.[1] || null,
|
language: event.language ?? null,
|
||||||
replies_count: event.event_stats?.replies_count ?? 0,
|
replies_count: event.event_stats?.replies_count ?? 0,
|
||||||
reblogs_count: event.event_stats?.reposts_count ?? 0,
|
reblogs_count: event.event_stats?.reposts_count ?? 0,
|
||||||
favourites_count: event.event_stats?.reactions['+'] ?? 0,
|
favourites_count: event.event_stats?.reactions['+'] ?? 0,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue