fix: quote field go only 1 level in depth and fetch quote event from database

This commit is contained in:
P. Reis 2024-04-12 11:41:13 -03:00
parent 77e5f4df2c
commit c6dce0e86b

View file

@ -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;