[mastodon-client] Refactor NoteHelpers

This commit is contained in:
Laura Hausmann 2023-09-15 14:05:17 +02:00
parent 777db83014
commit f384186b88
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
2 changed files with 10 additions and 5 deletions

View File

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

View File

@ -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<Note[]> {
public static async getNoteDescendants(note: Note | string, user?: ILocalUser, limit: number = 10, depth: number = 2): Promise<Note[]> {
const noteId = typeof note === "string" ? note : note.id;
const query = makePaginationQuery(Notes.createQueryBuilder("note"))
.andWhere(