2020-01-29 19:37:25 +00:00
|
|
|
import $ from 'cafy';
|
2021-08-19 12:55:45 +00:00
|
|
|
import { ID } from '@/misc/cafy-id';
|
|
|
|
import define from '../../define';
|
2021-09-18 04:30:28 +00:00
|
|
|
import readNote from '@/services/note/read';
|
2021-08-19 12:55:45 +00:00
|
|
|
import { Antennas, Notes, AntennaNotes } from '@/models/index';
|
|
|
|
import { makePaginationQuery } from '../../common/make-pagination-query';
|
|
|
|
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
|
|
|
|
import { generateMutedUserQuery } from '../../common/generate-muted-user-query';
|
|
|
|
import { ApiError } from '../../error';
|
|
|
|
import { generateBlockedUserQuery } from '../../common/generate-block-query';
|
2020-01-29 19:37:25 +00:00
|
|
|
|
|
|
|
export const meta = {
|
2020-04-03 13:42:29 +00:00
|
|
|
tags: ['antennas', 'account', 'notes'],
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-02-15 12:33:32 +00:00
|
|
|
requireCredential: true as const,
|
2020-01-29 19:37:25 +00:00
|
|
|
|
|
|
|
kind: 'read:account',
|
|
|
|
|
|
|
|
params: {
|
|
|
|
antennaId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
},
|
|
|
|
|
|
|
|
limit: {
|
|
|
|
validator: $.optional.num.range(1, 100),
|
2021-12-09 14:58:30 +00:00
|
|
|
default: 10,
|
2020-01-29 19:37:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sinceId: {
|
|
|
|
validator: $.optional.type(ID),
|
|
|
|
},
|
|
|
|
|
|
|
|
untilId: {
|
|
|
|
validator: $.optional.type(ID),
|
|
|
|
},
|
2021-11-28 04:45:17 +00:00
|
|
|
|
|
|
|
sinceDate: {
|
|
|
|
validator: $.optional.num,
|
|
|
|
},
|
|
|
|
|
|
|
|
untilDate: {
|
|
|
|
validator: $.optional.num,
|
|
|
|
},
|
2020-01-29 19:37:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchAntenna: {
|
|
|
|
message: 'No such antenna.',
|
|
|
|
code: 'NO_SUCH_ANTENNA',
|
2021-12-09 14:58:30 +00:00
|
|
|
id: '850926e0-fd3b-49b6-b69a-b28a5dbd82fe',
|
|
|
|
},
|
2021-03-06 13:34:11 +00: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,
|
2021-12-09 14:58:30 +00:00
|
|
|
ref: 'Note',
|
|
|
|
},
|
|
|
|
},
|
2020-01-29 19:37:25 +00:00
|
|
|
};
|
|
|
|
|
2022-01-02 17:12:50 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2020-01-29 19:37:25 +00:00
|
|
|
export default define(meta, async (ps, user) => {
|
|
|
|
const antenna = await Antennas.findOne({
|
|
|
|
id: ps.antennaId,
|
2021-12-09 14:58:30 +00:00
|
|
|
userId: user.id,
|
2020-01-29 19:37:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (antenna == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchAntenna);
|
|
|
|
}
|
|
|
|
|
|
|
|
const antennaQuery = AntennaNotes.createQueryBuilder('joining')
|
|
|
|
.select('joining.noteId')
|
|
|
|
.where('joining.antennaId = :antennaId', { antennaId: antenna.id });
|
|
|
|
|
2021-11-28 04:45:17 +00:00
|
|
|
const query = makePaginationQuery(Notes.createQueryBuilder('note'),
|
|
|
|
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
|
2020-01-29 19:37:25 +00:00
|
|
|
.andWhere(`note.id IN (${ antennaQuery.getQuery() })`)
|
2021-03-21 03:33:37 +00:00
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
2021-03-21 03:31:56 +00:00
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser')
|
2020-01-29 19:37:25 +00:00
|
|
|
.setParameters(antennaQuery.getParameters());
|
|
|
|
|
|
|
|
generateVisibilityQuery(query, user);
|
2020-07-28 00:38:41 +00:00
|
|
|
generateMutedUserQuery(query, user);
|
2021-08-17 12:48:59 +00:00
|
|
|
generateBlockedUserQuery(query, user);
|
2020-01-29 19:37:25 +00:00
|
|
|
|
|
|
|
const notes = await query
|
|
|
|
.take(ps.limit!)
|
|
|
|
.getMany();
|
|
|
|
|
2021-09-18 04:30:28 +00:00
|
|
|
if (notes.length > 0) {
|
|
|
|
readNote(user.id, notes);
|
|
|
|
}
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
return await Notes.packMany(notes, user);
|
|
|
|
});
|