Add MastodonAttachment type

This commit is contained in:
Alex Gleason 2024-08-07 21:19:04 -05:00
parent efc121a4ae
commit 313c37564c
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
4 changed files with 25 additions and 12 deletions

View file

@ -0,0 +1,15 @@
export interface MastodonAttachment {
id: string;
type: string;
url: string;
preview_url?: string;
remote_url?: string | null;
description?: string;
blurhash?: string | null;
meta?: {
original?: {
width?: number;
height?: number;
};
};
}

View file

@ -1,4 +1,5 @@
import { MastodonAccount } from '@/entities/MastodonAccount.ts'; import { MastodonAccount } from '@/entities/MastodonAccount.ts';
import { MastodonAttachment } from '@/entities/MastodonAttachment.ts';
import { PreviewCard } from '@/entities/PreviewCard.ts'; import { PreviewCard } from '@/entities/PreviewCard.ts';
export interface MastodonStatus { export interface MastodonStatus {
@ -24,16 +25,7 @@ export interface MastodonStatus {
pinned: boolean; pinned: boolean;
reblog: MastodonStatus | null; reblog: MastodonStatus | null;
application: unknown; application: unknown;
media_attachments: { media_attachments: MastodonAttachment[];
type: string;
preview_url?: string;
meta?: {
original?: {
width?: number;
height?: number;
};
};
}[];
mentions: unknown[]; mentions: unknown[];
tags: unknown[]; tags: unknown[];
emojis: unknown[]; emojis: unknown[];

View file

@ -1,7 +1,10 @@
import { MastodonAttachment } from '@/entities/MastodonAttachment.ts';
import { getUrlMediaType } from '@/utils/media.ts'; import { getUrlMediaType } from '@/utils/media.ts';
/** Render Mastodon media attachment. */ /** Render Mastodon media attachment. */
function renderAttachment(media: { id?: string; data: string[][] }) { function renderAttachment(
media: { id?: string; data: string[][] },
): (MastodonAttachment & { cid?: string }) | undefined {
const { id, data: tags } = media; const { id, data: tags } = media;
const url = tags.find(([name]) => name === 'url')?.[1]; const url = tags.find(([name]) => name === 'url')?.[1];

View file

@ -2,6 +2,7 @@ import { NostrEvent } from '@nostrify/nostrify';
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { MastodonAttachment } from '@/entities/MastodonAttachment.ts';
import { MastodonMention } from '@/entities/MastodonMention.ts'; import { MastodonMention } from '@/entities/MastodonMention.ts';
import { MastodonStatus } from '@/entities/MastodonStatus.ts'; import { MastodonStatus } from '@/entities/MastodonStatus.ts';
import { type DittoEvent } from '@/interfaces/DittoEvent.ts'; import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
@ -119,7 +120,9 @@ async function renderStatus(event: DittoEvent, opts: RenderStatusOpts): Promise<
pinned: Boolean(pinEvent), pinned: Boolean(pinEvent),
reblog: null, reblog: null,
application: null, application: null,
media_attachments: media.map((m) => renderAttachment({ data: m })).filter(Boolean), media_attachments: media.map((m) => renderAttachment({ data: m })).filter((m): m is MastodonAttachment =>
Boolean(m)
),
mentions, mentions,
tags: [], tags: [],
emojis: renderEmojis(event), emojis: renderEmojis(event),