From b3c186a14a3b8384029bb4efac95d473180a9a49 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sun, 8 Oct 2023 01:00:16 +0200 Subject: [PATCH] [mastodon-client] Only encode renote once in NoteConverter --- .../backend/src/server/api/mastodon/converters/note.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/converters/note.ts b/packages/backend/src/server/api/mastodon/converters/note.ts index 917c28ec9..111ee33ee 100644 --- a/packages/backend/src/server/api/mastodon/converters/note.ts +++ b/packages/backend/src/server/api/mastodon/converters/note.ts @@ -61,7 +61,7 @@ export class NoteConverter { } }) : null; - const renote = note.renote ?? (note.renoteId ? getNote(note.renoteId, user) : null); + const renote = note.renote ?? (note.renoteId && recurse ? getNote(note.renoteId, user) : null); const isBookmarked = user ? NoteFavorites.exist({ where: { @@ -103,6 +103,8 @@ export class NoteConverter { } as MastodonEntity.Tag; }); + const reblog = Promise.resolve(renote).then(renote => recurse && renote ? this.encode(renote, ctx, false) : null); + // noinspection ES6MissingAwait return await awaitAll({ id: note.id, @@ -111,7 +113,7 @@ export class NoteConverter { account: Promise.resolve(noteUser).then(p => UserConverter.encode(p, ctx)), in_reply_to_id: note.replyId, in_reply_to_account_id: note.replyUserId, - reblog: Promise.resolve(renote).then(renote => recurse && renote && note.text === null ? this.encode(renote, ctx, false) : null), + reblog: reblog.then(reblog => note.text === null ? reblog : null), content: text.then(text => text !== null ? MfmHelpers.toHtml(mfm.parse(text), JSON.parse(note.mentionedRemoteUsers)) ?? escapeMFM(text) : ""), text: text, created_at: note.createdAt.toISOString(), @@ -135,7 +137,7 @@ export class NoteConverter { pinned: isPinned, reactions: populated.then(populated => Promise.resolve(reaction).then(reaction => this.encodeReactions(note.reactions, reaction?.reaction, populated))), bookmarked: isBookmarked, - quote: Promise.resolve(renote).then(renote => recurse && renote && note.text !== null ? this.encode(renote, ctx, false) : null), + quote: reblog.then(reblog => note.text !== null ? reblog : null), edited_at: note.updatedAt?.toISOString() }); }