2020-01-29 20:37:25 +01:00
|
|
|
import $ from 'cafy';
|
2021-08-19 11:33:41 +02:00
|
|
|
import { ID } from '@/misc/cafy-id.js';
|
|
|
|
import define from '../../define.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
|
|
|
|
2020-02-15 13:33:32 +01:00
|
|
|
requireCredential: true as const,
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
kind: 'read:account',
|
|
|
|
|
|
|
|
params: {
|
|
|
|
antennaId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
},
|
|
|
|
|
|
|
|
limit: {
|
|
|
|
validator: $.optional.num.range(1, 100),
|
|
|
|
default: 10
|
|
|
|
},
|
|
|
|
|
|
|
|
sinceId: {
|
|
|
|
validator: $.optional.type(ID),
|
|
|
|
},
|
|
|
|
|
|
|
|
untilId: {
|
|
|
|
validator: $.optional.type(ID),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchAntenna: {
|
|
|
|
message: 'No such antenna.',
|
|
|
|
code: 'NO_SUCH_ANTENNA',
|
|
|
|
id: '850926e0-fd3b-49b6-b69a-b28a5dbd82fe'
|
|
|
|
}
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
|
|
|
type: 'array' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
items: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
ref: 'Note'
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default define(meta, async (ps, user) => {
|
|
|
|
const antenna = await Antennas.findOne({
|
|
|
|
id: ps.antennaId,
|
|
|
|
userId: user.id
|
|
|
|
});
|
|
|
|
|
|
|
|
if (antenna == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchAntenna);
|
|
|
|
}
|
|
|
|
|
|
|
|
const antennaQuery = AntennaNotes.createQueryBuilder('joining')
|
|
|
|
.select('joining.noteId')
|
|
|
|
.where('joining.antennaId = :antennaId', { antennaId: antenna.id });
|
|
|
|
|
|
|
|
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId)
|
|
|
|
.andWhere(`note.id IN (${ antennaQuery.getQuery() })`)
|
2021-03-21 04:33:37 +01:00
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
2021-03-21 04:31:56 +01:00
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser')
|
2020-01-29 20:37:25 +01:00
|
|
|
.setParameters(antennaQuery.getParameters());
|
|
|
|
|
|
|
|
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
|
|
|
|
.take(ps.limit!)
|
|
|
|
.getMany();
|
|
|
|
|
|
|
|
return await Notes.packMany(notes, user);
|
|
|
|
});
|