diff --git a/src/views/mastodon/statuses.ts b/src/views/mastodon/statuses.ts index 43f73cf8..0f16f4bb 100644 --- a/src/views/mastodon/statuses.ts +++ b/src/views/mastodon/statuses.ts @@ -68,6 +68,7 @@ async function renderStatus(event: DittoEvent, viewerPubkey?: string) { const media = [...mediaLinks, ...mediaTags]; const quoteId = event.tags.find(([name]) => name === 'q')?.[1]; + const [quoteStatus, depth] = await renderQuoteRepost(quoteId, 1); return { id: event.id, @@ -99,10 +100,33 @@ async function renderStatus(event: DittoEvent, viewerPubkey?: string) { uri: Conf.external(note), url: Conf.external(note), zapped: Boolean(zapEvent), - quote: !quoteId ? null : quoteId, + quote: depth < 1 && quoteStatus + ? quoteStatus + : depth > 0 && quoteStatus + ? (await renderQuoteRepost(quoteId, depth - 1))[0] + : null, }; } +async function renderQuoteRepost(quoteId: string | undefined, depth: number): Promise<[any, number]> { + if (depth < 1) return [null, depth]; + + if (!quoteId) return [null, depth]; + + const quottedEvent = await getEvent(quoteId, { kind: 1 }); + if (!quottedEvent) return [null, depth]; + + if (depth === 1) { + quottedEvent.tags = quottedEvent.tags.filter(([name]) => name !== 'q'); + } + + const status = await renderStatus(quottedEvent); + if (!status) return [null, depth]; + + depth--; + return [status, depth]; +} + async function renderReblog(event: DittoEvent) { if (!event.author) return;