2023-01-13 05:40:33 +01:00
|
|
|
import define from "../../define.js";
|
|
|
|
import readNote from "@/services/note/read.js";
|
|
|
|
import { Antennas, Notes, AntennaNotes } from "@/models/index.js";
|
|
|
|
import { makePaginationQuery } from "../../common/make-pagination-query.js";
|
|
|
|
import { generateVisibilityQuery } from "../../common/generate-visibility-query.js";
|
|
|
|
import { generateMutedUserQuery } from "../../common/generate-muted-user-query.js";
|
|
|
|
import { ApiError } from "../../error.js";
|
|
|
|
import { generateBlockedUserQuery } from "../../common/generate-block-query.js";
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
export const meta = {
|
2023-01-13 05:40:33 +01:00
|
|
|
tags: ["antennas", "account", "notes"],
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: true,
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
kind: "read:account",
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchAntenna: {
|
2023-01-13 05:40:33 +01:00
|
|
|
message: "No such antenna.",
|
|
|
|
code: "NO_SUCH_ANTENNA",
|
|
|
|
id: "850926e0-fd3b-49b6-b69a-b28a5dbd82fe",
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "array",
|
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
2021-03-06 14:34:11 +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
|
|
|
},
|
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2020-01-29 20:37:25 +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
|
|
|
antennaId: { 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" },
|
|
|
|
sinceDate: { type: "integer" },
|
|
|
|
untilDate: { type: "integer" },
|
2022-02-19 06:05:32 +01:00
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
required: ["antennaId"],
|
2022-02-19 06:05:32 +01:00
|
|
|
} as const;
|
|
|
|
|
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2022-03-26 07:34:00 +01:00
|
|
|
const antenna = await Antennas.findOneBy({
|
2020-01-29 20:37:25 +01:00
|
|
|
id: ps.antennaId,
|
2021-12-09 15:58:30 +01:00
|
|
|
userId: user.id,
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if (antenna == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchAntenna);
|
|
|
|
}
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
const query = makePaginationQuery(
|
|
|
|
Notes.createQueryBuilder("note"),
|
|
|
|
ps.sinceId,
|
|
|
|
ps.untilId,
|
|
|
|
ps.sinceDate,
|
|
|
|
ps.untilDate,
|
|
|
|
)
|
|
|
|
.innerJoin(
|
|
|
|
AntennaNotes.metadata.targetName,
|
|
|
|
"antennaNote",
|
|
|
|
"antennaNote.noteId = 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")
|
|
|
|
.andWhere("antennaNote.antennaId = :antennaId", { antennaId: antenna.id });
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
generateVisibilityQuery(query, user);
|
2020-07-28 02:38:41 +02:00
|
|
|
generateMutedUserQuery(query, user);
|
2021-08-17 14:48:59 +02:00
|
|
|
generateBlockedUserQuery(query, user);
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
const notes = await query.take(ps.limit).getMany();
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2021-09-18 06:30:28 +02:00
|
|
|
if (notes.length > 0) {
|
|
|
|
readNote(user.id, notes);
|
|
|
|
}
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
return await Notes.packMany(notes, user);
|
|
|
|
});
|