From 77e5f4df2c8624b5de1be65ec734263fe7eca103 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Thu, 11 Apr 2024 18:56:50 -0300 Subject: [PATCH] feat: quote repost --- src/controllers/api/instance.ts | 1 + src/controllers/api/statuses.ts | 5 +++++ src/views/mastodon/statuses.ts | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/controllers/api/instance.ts b/src/controllers/api/instance.ts index 15a99c31..1355330f 100644 --- a/src/controllers/api/instance.ts +++ b/src/controllers/api/instance.ts @@ -42,6 +42,7 @@ const instanceController: AppController = async (c) => { 'mastodon_api', 'mastodon_api_streaming', 'exposable_reactions', + 'quote_posting', ], }, }, diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index b8873a92..afd3673c 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -28,6 +28,7 @@ const createStatusSchema = z.object({ spoiler_text: z.string().nullish(), status: z.string().nullish(), visibility: z.enum(['public', 'unlisted', 'private', 'direct']).nullish(), + quote_id: z.string().nullish(), }).refine( (data) => Boolean(data.status || data.media_ids?.length), { message: 'Status must contain text or media.' }, @@ -69,6 +70,10 @@ const createStatusController: AppController = async (c) => { const tags: string[][] = []; + if (data.quote_id) { + tags.push(['q', data.quote_id]); + } + if (data.in_reply_to_id) { tags.push(['e', data.in_reply_to_id, 'reply']); } diff --git a/src/views/mastodon/statuses.ts b/src/views/mastodon/statuses.ts index 6762e82d..43f73cf8 100644 --- a/src/views/mastodon/statuses.ts +++ b/src/views/mastodon/statuses.ts @@ -67,6 +67,8 @@ async function renderStatus(event: DittoEvent, viewerPubkey?: string) { const media = [...mediaLinks, ...mediaTags]; + const quoteId = event.tags.find(([name]) => name === 'q')?.[1]; + return { id: event.id, account, @@ -97,6 +99,7 @@ async function renderStatus(event: DittoEvent, viewerPubkey?: string) { uri: Conf.external(note), url: Conf.external(note), zapped: Boolean(zapEvent), + quote: !quoteId ? null : quoteId, }; }