2023-01-13 05:40:33 +01:00
|
|
|
import { Notes } from "@/models/index.js";
|
|
|
|
import define from "../../define.js";
|
|
|
|
import { getNote } from "../../common/getters.js";
|
|
|
|
import { ApiError } from "../../error.js";
|
|
|
|
import { generateVisibilityQuery } from "../../common/generate-visibility-query.js";
|
|
|
|
import { generateMutedUserQuery } from "../../common/generate-muted-user-query.js";
|
|
|
|
import { makePaginationQuery } from "../../common/make-pagination-query.js";
|
|
|
|
import { generateBlockedUserQuery } from "../../common/generate-block-query.js";
|
2018-11-01 19:32:24 +01:00
|
|
|
|
|
|
|
export const meta = {
|
2023-01-13 05:40:33 +01:00
|
|
|
tags: ["notes"],
|
2019-02-23 03:20:58 +01:00
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: false,
|
2021-07-20 20:51:59 +02:00
|
|
|
requireCredentialPrivateMode: true,
|
2018-11-01 19:32:24 +01:00
|
|
|
|
2019-02-23 03:20:58 +01:00
|
|
|
res: {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "array",
|
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
2019-02-23 03:20:58 +01:00
|
|
|
items: {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "object",
|
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
|
|
|
ref: "Note",
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
2019-02-23 03:20:58 +01:00
|
|
|
},
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
errors: {
|
|
|
|
noSuchNote: {
|
2023-01-13 05:40:33 +01:00
|
|
|
message: "No such note.",
|
|
|
|
code: "NO_SUCH_NOTE",
|
|
|
|
id: "12908022-2e21-46cd-ba6a-3edaf6093f46",
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2018-11-01 19:32:24 +01:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "object",
|
2022-02-19 06:05:32 +01:00
|
|
|
properties: {
|
2023-01-13 05:40:33 +01:00
|
|
|
noteId: { type: "string", format: "misskey:id" },
|
|
|
|
limit: { type: "integer", minimum: 1, maximum: 100, default: 10 },
|
|
|
|
sinceId: { type: "string", format: "misskey:id" },
|
|
|
|
untilId: { type: "string", format: "misskey:id" },
|
2022-02-19 06:05:32 +01:00
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
required: ["noteId"],
|
2022-02-19 06:05:32 +01:00
|
|
|
} as const;
|
|
|
|
|
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
const note = await getNote(ps.noteId, user).catch((err) => {
|
|
|
|
if (err.id === "9725d0ce-ba28-4dde-95a7-2cbb2c15de24")
|
|
|
|
throw new ApiError(meta.errors.noSuchNote);
|
2022-07-25 18:15:21 +02:00
|
|
|
throw err;
|
2018-11-01 19:32:24 +01:00
|
|
|
});
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
const query = makePaginationQuery(
|
|
|
|
Notes.createQueryBuilder("note"),
|
|
|
|
ps.sinceId,
|
|
|
|
ps.untilId,
|
|
|
|
)
|
|
|
|
.andWhere("note.renoteId = :renoteId", { renoteId: note.id })
|
|
|
|
.innerJoinAndSelect("note.user", "user")
|
|
|
|
.leftJoinAndSelect("user.avatar", "avatar")
|
|
|
|
.leftJoinAndSelect("user.banner", "banner")
|
|
|
|
.leftJoinAndSelect("note.reply", "reply")
|
|
|
|
.leftJoinAndSelect("note.renote", "renote")
|
|
|
|
.leftJoinAndSelect("reply.user", "replyUser")
|
|
|
|
.leftJoinAndSelect("replyUser.avatar", "replyUserAvatar")
|
|
|
|
.leftJoinAndSelect("replyUser.banner", "replyUserBanner")
|
|
|
|
.leftJoinAndSelect("renote.user", "renoteUser")
|
|
|
|
.leftJoinAndSelect("renoteUser.avatar", "renoteUserAvatar")
|
|
|
|
.leftJoinAndSelect("renoteUser.banner", "renoteUserBanner");
|
2018-11-01 19:32:24 +01:00
|
|
|
|
2019-12-11 16:49:30 +01:00
|
|
|
generateVisibilityQuery(query, user);
|
2020-07-28 02:38:41 +02:00
|
|
|
if (user) generateMutedUserQuery(query, user);
|
2021-08-17 14:48:59 +02:00
|
|
|
if (user) generateBlockedUserQuery(query, user);
|
2018-11-01 19:32:24 +01:00
|
|
|
|
2023-04-03 18:46:06 +02:00
|
|
|
// We fetch more than requested because some may be filtered out, and if there's less than
|
|
|
|
// requested, the pagination stops.
|
|
|
|
const found = [];
|
|
|
|
const take = Math.floor(ps.limit * 1.5);
|
|
|
|
let skip = 0;
|
|
|
|
while (found.length < ps.limit) {
|
|
|
|
const notes = await query.take(take).skip(skip).getMany();
|
2023-04-07 03:56:46 +02:00
|
|
|
found.push(...(await Notes.packMany(notes, user)));
|
2023-04-03 18:46:06 +02:00
|
|
|
skip += take;
|
|
|
|
if (notes.length < take) break;
|
|
|
|
}
|
2018-11-01 19:32:24 +01:00
|
|
|
|
2023-04-03 18:46:06 +02:00
|
|
|
if (found.length > ps.limit) {
|
|
|
|
found.length = ps.limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
2019-02-22 03:46:58 +01:00
|
|
|
});
|