From fc325880d2270eaf4f779087502b5cc1b2b85fc2 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 21 May 2024 14:27:49 -0500 Subject: [PATCH] Add root tags to replies --- src/controllers/api/statuses.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index e9c872f..58526cb 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -76,12 +76,21 @@ const createStatusController: AppController = async (c) => { const tags: string[][] = []; - if (data.quote_id) { - tags.push(['q', data.quote_id]); + if (data.in_reply_to_id) { + const ancestor = await getEvent(data.in_reply_to_id); + + if (!ancestor) { + return c.json({ error: 'Original post not found.' }, 404); + } + + const root = ancestor.tags.find((tag) => tag[0] === 'e' && tag[3] === 'root')?.[1] ?? ancestor.id; + + tags.push(['e', root, 'root']); + tags.push(['e', data.in_reply_to_id, 'reply']); } - if (data.in_reply_to_id) { - tags.push(['e', data.in_reply_to_id, 'reply']); + if (data.quote_id) { + tags.push(['q', data.quote_id]); } if (data.sensitive && data.spoiler_text) {