[mastodon-client] Implement NoteConverter.encodeMany function

This commit is contained in:
Laura Hausmann 2023-09-15 13:56:43 +02:00
parent e1e4160a62
commit 777db83014
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
2 changed files with 14 additions and 6 deletions

View File

@ -108,4 +108,9 @@ export class NoteConverter {
quote: note.renote && note.text ? await this.encode(note.renote, user) : null,
};
}
public static async encodeMany(notes: Note[], user?: ILocalUser): Promise<MastodonEntity.Status[]> {
const encoded = notes.map(n => this.encode(n, user));
return Promise.all(encoded);
}
}

View File

@ -10,6 +10,7 @@ import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
import { getNote } from "@/server/api/common/getters.js";
import authenticate from "@/server/api/authenticate.js";
import { NoteHelpers } from "@/server/api/mastodon/helpers/note.js";
import { Note } from "@/models/entities/note.js";
function normalizeQuery(data: any) {
const str = querystring.stringify(data);
@ -64,7 +65,7 @@ export function apiStatusMastodon(router: Router): void {
convertId(p, IdType.IceshrimpId),
);
}
const { sensitive } = body;
const {sensitive} = body;
body.sensitive =
typeof sensitive === "string" ? sensitive === "true" : sensitive;
@ -114,7 +115,7 @@ export function apiStatusMastodon(router: Router): void {
convertId(p, IdType.IceshrimpId),
);
}
const { sensitive } = body;
const {sensitive} = body;
body.sensitive =
typeof sensitive === "string" ? sensitive === "true" : sensitive;
@ -180,12 +181,14 @@ export function apiStatusMastodon(router: Router): void {
ctx.body = e.response.data;
}
});
interface IReaction {
id: string;
createdAt: string;
user: MisskeyEntity.User;
type: string;
}
router.get<{ Params: { id: string } }>(
"/v1/statuses/:id/context",
async (ctx) => {
@ -203,11 +206,11 @@ export function apiStatusMastodon(router: Router): void {
}
}
let ancestors = await NoteHelpers.getNoteAncestors(note, user, user ? 4096 : 60);
let children = await NoteHelpers.getNoteChildren(note, user, user ? 4096 : 40, user ? 4096 : 20);
const ancestors = await NoteHelpers.getNoteAncestors(note, user, user ? 4096 : 60);
const children = await NoteHelpers.getNoteChildren(note, user, user ? 4096 : 40, user ? 4096 : 20);
ctx.body = {
ancestors: (await Promise.all(ancestors.map(n => NoteConverter.encode(n, user)))).map(s => convertStatus(s)),
descendants: (await Promise.all(children.map(n => NoteConverter.encode(n, user)))).map(s => convertStatus(s)),
ancestors: (await NoteConverter.encodeMany(ancestors, user)).map((s: MastodonEntity.Status) => convertStatus(s)),
descendants: (await NoteConverter.encodeMany(children, user)).map((s: MastodonEntity.Status) => convertStatus(s)),
};
} catch (e: any) {
console.error(e);