mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2025-01-25 06:41:36 -07:00
[mastodon-client] Implement NoteConverter.encodeMany function
This commit is contained in:
parent
e1e4160a62
commit
777db83014
2 changed files with 14 additions and 6 deletions
|
@ -108,4 +108,9 @@ export class NoteConverter {
|
||||||
quote: note.renote && note.text ? await this.encode(note.renote, user) : null,
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { NoteConverter } from "@/server/api/mastodon/converters/note.js";
|
||||||
import { getNote } from "@/server/api/common/getters.js";
|
import { getNote } from "@/server/api/common/getters.js";
|
||||||
import authenticate from "@/server/api/authenticate.js";
|
import authenticate from "@/server/api/authenticate.js";
|
||||||
import { NoteHelpers } from "@/server/api/mastodon/helpers/note.js";
|
import { NoteHelpers } from "@/server/api/mastodon/helpers/note.js";
|
||||||
|
import { Note } from "@/models/entities/note.js";
|
||||||
|
|
||||||
function normalizeQuery(data: any) {
|
function normalizeQuery(data: any) {
|
||||||
const str = querystring.stringify(data);
|
const str = querystring.stringify(data);
|
||||||
|
@ -64,7 +65,7 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
convertId(p, IdType.IceshrimpId),
|
convertId(p, IdType.IceshrimpId),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const { sensitive } = body;
|
const {sensitive} = body;
|
||||||
body.sensitive =
|
body.sensitive =
|
||||||
typeof sensitive === "string" ? sensitive === "true" : sensitive;
|
typeof sensitive === "string" ? sensitive === "true" : sensitive;
|
||||||
|
|
||||||
|
@ -114,7 +115,7 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
convertId(p, IdType.IceshrimpId),
|
convertId(p, IdType.IceshrimpId),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const { sensitive } = body;
|
const {sensitive} = body;
|
||||||
body.sensitive =
|
body.sensitive =
|
||||||
typeof sensitive === "string" ? sensitive === "true" : sensitive;
|
typeof sensitive === "string" ? sensitive === "true" : sensitive;
|
||||||
|
|
||||||
|
@ -180,12 +181,14 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
ctx.body = e.response.data;
|
ctx.body = e.response.data;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
interface IReaction {
|
interface IReaction {
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
user: MisskeyEntity.User;
|
user: MisskeyEntity.User;
|
||||||
type: string;
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
router.get<{ Params: { id: string } }>(
|
router.get<{ Params: { id: string } }>(
|
||||||
"/v1/statuses/:id/context",
|
"/v1/statuses/:id/context",
|
||||||
async (ctx) => {
|
async (ctx) => {
|
||||||
|
@ -203,11 +206,11 @@ export function apiStatusMastodon(router: Router): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ancestors = await NoteHelpers.getNoteAncestors(note, user, user ? 4096 : 60);
|
const ancestors = await NoteHelpers.getNoteAncestors(note, user, user ? 4096 : 60);
|
||||||
let children = await NoteHelpers.getNoteChildren(note, user, user ? 4096 : 40, user ? 4096 : 20);
|
const children = await NoteHelpers.getNoteChildren(note, user, user ? 4096 : 40, user ? 4096 : 20);
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
ancestors: (await Promise.all(ancestors.map(n => NoteConverter.encode(n, user)))).map(s => convertStatus(s)),
|
ancestors: (await NoteConverter.encodeMany(ancestors, user)).map((s: MastodonEntity.Status) => convertStatus(s)),
|
||||||
descendants: (await Promise.all(children.map(n => NoteConverter.encode(n, user)))).map(s => convertStatus(s)),
|
descendants: (await NoteConverter.encodeMany(children, user)).map((s: MastodonEntity.Status) => convertStatus(s)),
|
||||||
};
|
};
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
Loading…
Reference in a new issue