From f384186b8849ced51fc7058ece7730c388e118a7 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 15 Sep 2023 14:05:17 +0200 Subject: [PATCH] [mastodon-client] Refactor NoteHelpers --- .../src/server/api/mastodon/endpoints/status.ts | 13 +++++++++---- .../backend/src/server/api/mastodon/helpers/note.ts | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index 73c013161..82cb82209 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -206,11 +206,16 @@ export function apiStatusMastodon(router: Router): void { } } - const ancestors = await NoteHelpers.getNoteAncestors(note, user, user ? 4096 : 60); - const children = await NoteHelpers.getNoteChildren(note, user, user ? 4096 : 40, user ? 4096 : 20); + const ancestors = await NoteHelpers.getNoteAncestors(note, user, user ? 4096 : 60) + .then(n => NoteConverter.encodeMany(n)) + .then(n => n.map(s => convertStatus(s))); + const descendants = await NoteHelpers.getNoteDescendants(note, user, user ? 4096 : 40, user ? 4096 : 20) + .then(n => NoteConverter.encodeMany(n)) + .then(n => n.map(s => convertStatus(s))); + ctx.body = { - ancestors: (await NoteConverter.encodeMany(ancestors, user)).map((s: MastodonEntity.Status) => convertStatus(s)), - descendants: (await NoteConverter.encodeMany(children, user)).map((s: MastodonEntity.Status) => convertStatus(s)), + ancestors, + descendants, }; } catch (e: any) { console.error(e); diff --git a/packages/backend/src/server/api/mastodon/helpers/note.ts b/packages/backend/src/server/api/mastodon/helpers/note.ts index e46796e35..0088857cd 100644 --- a/packages/backend/src/server/api/mastodon/helpers/note.ts +++ b/packages/backend/src/server/api/mastodon/helpers/note.ts @@ -9,7 +9,7 @@ import querystring from "node:querystring"; import { getNote } from "@/server/api/common/getters.js"; export class NoteHelpers { - public static async getNoteChildren(note: Note | string, user?: ILocalUser, limit: number = 10, depth: number = 2): Promise { + public static async getNoteDescendants(note: Note | string, user?: ILocalUser, limit: number = 10, depth: number = 2): Promise { const noteId = typeof note === "string" ? note : note.id; const query = makePaginationQuery(Notes.createQueryBuilder("note")) .andWhere(