2022-06-14 09:01:23 +00:00
|
|
|
import { Brackets } from 'typeorm';
|
|
|
|
import { Notes } from '@/models/index.js';
|
2022-02-27 02:07:39 +00:00
|
|
|
import define from '../../define.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 { generateBlockedUserQuery } from '../../common/generate-block-query.js';
|
2019-03-07 04:03:46 +00:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['notes'],
|
|
|
|
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: false,
|
2019-03-07 04:03:46 +00:00
|
|
|
|
|
|
|
res: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2019-03-07 04:03:46 +00:00
|
|
|
items: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-04-23 13:35:26 +00:00
|
|
|
ref: 'Note',
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2019-03-07 04:03:46 +00:00
|
|
|
},
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2019-03-07 04:03:46 +00:00
|
|
|
|
2022-02-20 04:15:40 +00:00
|
|
|
export const paramDef = {
|
2022-02-19 05:05:32 +00:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
noteId: { 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: ['noteId'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 17:12:50 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 05:05:32 +00:00
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId)
|
|
|
|
.andWhere(new Brackets(qb => { qb
|
2022-06-14 09:01:23 +00:00
|
|
|
.where('note.replyId = :noteId', { noteId: ps.noteId })
|
2019-04-07 12:50:36 +00:00
|
|
|
.orWhere(new Brackets(qb => { qb
|
2022-06-14 09:01:23 +00:00
|
|
|
.where('note.renoteId = :noteId', { noteId: ps.noteId })
|
2019-04-07 12:50:36 +00:00
|
|
|
.andWhere(new Brackets(qb => { qb
|
2022-06-14 09:01:23 +00:00
|
|
|
.where('note.text IS NOT NULL')
|
|
|
|
.orWhere('note.fileIds != \'{}\'')
|
|
|
|
.orWhere('note.hasPoll = TRUE');
|
2019-04-07 12:50:36 +00:00
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}))
|
2021-03-21 03:33:37 +00:00
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
2022-02-27 04:59:10 +00:00
|
|
|
.leftJoinAndSelect('user.avatar', 'avatar')
|
|
|
|
.leftJoinAndSelect('user.banner', 'banner')
|
2021-03-21 03:31:56 +00:00
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
2022-02-27 04:59:10 +00:00
|
|
|
.leftJoinAndSelect('replyUser.avatar', 'replyUserAvatar')
|
|
|
|
.leftJoinAndSelect('replyUser.banner', 'replyUserBanner')
|
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser')
|
|
|
|
.leftJoinAndSelect('renoteUser.avatar', 'renoteUserAvatar')
|
|
|
|
.leftJoinAndSelect('renoteUser.banner', 'renoteUserBanner');
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2019-12-11 15:49:30 +00:00
|
|
|
generateVisibilityQuery(query, user);
|
2022-06-25 05:23:59 +00:00
|
|
|
if (user) {
|
|
|
|
generateMutedUserQuery(query, user);
|
|
|
|
generateBlockedUserQuery(query, user);
|
|
|
|
}
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2022-02-19 05:05:32 +00:00
|
|
|
const notes = await query.take(ps.limit).getMany();
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
return await Notes.packMany(notes, user);
|
2019-03-07 04:03:46 +00:00
|
|
|
});
|