mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-25 13:39:06 +01:00
[mastodon-client] Refactor NoteHelpers
This commit is contained in:
parent
777db83014
commit
f384186b88
2 changed files with 10 additions and 5 deletions
|
@ -206,11 +206,16 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ancestors = await NoteHelpers.getNoteAncestors(note, user, user ? 4096 : 60);
|
const ancestors = await NoteHelpers.getNoteAncestors(note, user, user ? 4096 : 60)
|
||||||
const children = await NoteHelpers.getNoteChildren(note, user, user ? 4096 : 40, user ? 4096 : 20);
|
.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 = {
|
ctx.body = {
|
||||||
ancestors: (await NoteConverter.encodeMany(ancestors, user)).map((s: MastodonEntity.Status) => convertStatus(s)),
|
ancestors,
|
||||||
descendants: (await NoteConverter.encodeMany(children, user)).map((s: MastodonEntity.Status) => convertStatus(s)),
|
descendants,
|
||||||
};
|
};
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
|
@ -9,7 +9,7 @@ import querystring from "node:querystring";
|
||||||
import { getNote } from "@/server/api/common/getters.js";
|
import { getNote } from "@/server/api/common/getters.js";
|
||||||
|
|
||||||
export class NoteHelpers {
|
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 noteId = typeof note === "string" ? note : note.id;
|
||||||
const query = makePaginationQuery(Notes.createQueryBuilder("note"))
|
const query = makePaginationQuery(Notes.createQueryBuilder("note"))
|
||||||
.andWhere(
|
.andWhere(
|
||||||
|
|
Loading…
Reference in a new issue