2021-08-19 15:55:45 +03:00
|
|
|
import define from '../../define';
|
|
|
|
import { ClipNotes, Clips, Notes } 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 21:37:25 +02:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['account', 'notes', 'clips'],
|
|
|
|
|
2022-01-18 15:27:10 +02:00
|
|
|
requireCredential: false,
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
kind: 'read:account',
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchClip: {
|
2020-11-15 05:04:54 +02:00
|
|
|
message: 'No such clip.',
|
2020-01-29 21:37:25 +02:00
|
|
|
code: 'NO_SUCH_CLIP',
|
2021-12-09 16:58:30 +02:00
|
|
|
id: '1d7645e6-2b6d-4635-b0fe-fe22b0e72e00',
|
|
|
|
},
|
2021-03-06 15:34:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 15:34:11 +02:00
|
|
|
items: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 16:58:30 +02:00
|
|
|
ref: 'Note',
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 15:27:10 +02:00
|
|
|
} as const;
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-02-19 07:05:32 +02:00
|
|
|
const paramDef = {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
clipId: { 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' },
|
|
|
|
},
|
|
|
|
required: ['clipId'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 19:12:50 +02:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 07:05:32 +02:00
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2020-01-29 21:37:25 +02:00
|
|
|
const clip = await Clips.findOne({
|
|
|
|
id: ps.clipId,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (clip == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchClip);
|
|
|
|
}
|
|
|
|
|
2020-11-15 10:35:40 +02:00
|
|
|
if (!clip.isPublic && (user == null || (clip.userId !== user.id))) {
|
2020-11-15 10:32:29 +02:00
|
|
|
throw new ApiError(meta.errors.noSuchClip);
|
|
|
|
}
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
const clipQuery = ClipNotes.createQueryBuilder('joining')
|
|
|
|
.select('joining.noteId')
|
|
|
|
.where('joining.clipId = :clipId', { clipId: clip.id });
|
|
|
|
|
|
|
|
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId)
|
|
|
|
.andWhere(`note.id IN (${ clipQuery.getQuery() })`)
|
2021-03-21 05:33:37 +02:00
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
2021-03-21 05:31:56 +02:00
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser')
|
2020-01-29 21:37:25 +02:00
|
|
|
.setParameters(clipQuery.getParameters());
|
|
|
|
|
2020-11-15 10:35:40 +02:00
|
|
|
if (user) {
|
|
|
|
generateVisibilityQuery(query, user);
|
|
|
|
generateMutedUserQuery(query, user);
|
2021-08-17 15:48:59 +03:00
|
|
|
generateBlockedUserQuery(query, user);
|
2020-11-15 10:35:40 +02:00
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
const notes = await query
|
2022-02-19 07:05:32 +02:00
|
|
|
.take(ps.limit)
|
2020-01-29 21:37:25 +02:00
|
|
|
.getMany();
|
|
|
|
|
|
|
|
return await Notes.packMany(notes, user);
|
|
|
|
});
|