2022-02-27 03:07:39 +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 = {
|
2020-04-03 15:42:29 +02: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
|
|
|
|
|
|
|
kind: 'read:account',
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchAntenna: {
|
|
|
|
message: 'No such antenna.',
|
|
|
|
code: 'NO_SUCH_ANTENNA',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: '850926e0-fd3b-49b6-b69a-b28a5dbd82fe',
|
|
|
|
},
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 14:34:11 +01:00
|
|
|
items: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 15:58:30 +01:00
|
|
|
ref: 'Note',
|
|
|
|
},
|
|
|
|
},
|
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 = {
|
2022-02-19 06:05:32 +01:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
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' },
|
|
|
|
},
|
|
|
|
required: ['antennaId'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 18:12:50 +01:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 06:05:32 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-11-28 05:45:17 +01:00
|
|
|
const query = makePaginationQuery(Notes.createQueryBuilder('note'),
|
|
|
|
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
|
2022-04-19 15:59:39 +02:00
|
|
|
.innerJoin(AntennaNotes.metadata.targetName, 'antennaNote', 'antennaNote.noteId = note.id')
|
2021-03-21 04:33:37 +01:00
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
2022-02-27 05:59:10 +01:00
|
|
|
.leftJoinAndSelect('user.avatar', 'avatar')
|
|
|
|
.leftJoinAndSelect('user.banner', 'banner')
|
2021-03-21 04:31:56 +01:00
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
2022-02-27 05:59:10 +01:00
|
|
|
.leftJoinAndSelect('replyUser.avatar', 'replyUserAvatar')
|
|
|
|
.leftJoinAndSelect('replyUser.banner', 'replyUserBanner')
|
2021-03-21 04:31:56 +01:00
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser')
|
2022-02-27 05:59:10 +01:00
|
|
|
.leftJoinAndSelect('renoteUser.avatar', 'renoteUserAvatar')
|
|
|
|
.leftJoinAndSelect('renoteUser.banner', 'renoteUserBanner')
|
2022-04-19 15:59:39 +02:00
|
|
|
.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
|
|
|
|
|
|
|
const notes = await query
|
2022-02-19 06:05:32 +01:00
|
|
|
.take(ps.limit)
|
2020-01-29 20:37:25 +01:00
|
|
|
.getMany();
|
|
|
|
|
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);
|
|
|
|
});
|