2022-02-27 11:07:39 +09:00
|
|
|
import define from '../define.js';
|
|
|
|
import { makePaginationQuery } from '../common/make-pagination-query.js';
|
|
|
|
import { Notes } from '@/models/index.js';
|
2018-09-05 23:55:51 +09:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 11:20:58 +09:00
|
|
|
tags: ['notes'],
|
|
|
|
|
2019-02-24 19:42:26 +09:00
|
|
|
res: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2019-02-24 19:42:26 +09:00
|
|
|
items: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-04-23 22:35:26 +09:00
|
|
|
ref: 'Note',
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
2019-02-24 19:42:26 +09:00
|
|
|
},
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2017-03-03 08:06:34 +09:00
|
|
|
|
2022-02-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
2022-04-03 13:57:26 +09:00
|
|
|
local: { type: 'boolean', default: false },
|
2022-02-19 14:05:32 +09:00
|
|
|
reply: { type: 'boolean' },
|
|
|
|
renote: { type: 'boolean' },
|
|
|
|
withFiles: { type: 'boolean' },
|
|
|
|
poll: { type: 'boolean' },
|
|
|
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
|
|
|
sinceId: { type: 'string', format: 'misskey:id' },
|
|
|
|
untilId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: [],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-03 02:12:50 +09:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 14:05:32 +09:00
|
|
|
export default define(meta, paramDef, async (ps) => {
|
2019-04-07 21:50:36 +09:00
|
|
|
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId)
|
|
|
|
.andWhere(`note.visibility = 'public'`)
|
|
|
|
.andWhere(`note.localOnly = FALSE`)
|
2021-03-21 12:33:37 +09:00
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
2022-02-27 13:59:10 +09:00
|
|
|
.leftJoinAndSelect('user.avatar', 'avatar')
|
|
|
|
.leftJoinAndSelect('user.banner', 'banner')
|
2021-03-21 12:31:56 +09:00
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
2022-02-27 13:59:10 +09:00
|
|
|
.leftJoinAndSelect('replyUser.avatar', 'replyUserAvatar')
|
|
|
|
.leftJoinAndSelect('replyUser.banner', 'replyUserBanner')
|
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser')
|
|
|
|
.leftJoinAndSelect('renoteUser.avatar', 'renoteUserAvatar')
|
|
|
|
.leftJoinAndSelect('renoteUser.banner', 'renoteUserBanner');
|
2017-03-03 08:06:34 +09:00
|
|
|
|
2018-09-05 23:55:51 +09:00
|
|
|
if (ps.local) {
|
2019-04-07 21:50:36 +09:00
|
|
|
query.andWhere('note.userHost IS NULL');
|
2018-05-23 15:25:15 +09:00
|
|
|
}
|
|
|
|
|
2022-04-03 15:33:22 +09:00
|
|
|
if (ps.reply !== undefined) {
|
2019-04-07 21:50:36 +09:00
|
|
|
query.andWhere(ps.reply ? 'note.replyId IS NOT NULL' : 'note.replyId IS NULL');
|
2017-03-19 15:23:30 +09:00
|
|
|
}
|
|
|
|
|
2022-04-03 15:33:22 +09:00
|
|
|
if (ps.renote !== undefined) {
|
2019-04-07 21:50:36 +09:00
|
|
|
query.andWhere(ps.renote ? 'note.renoteId IS NOT NULL' : 'note.renoteId IS NULL');
|
2017-03-19 15:23:30 +09:00
|
|
|
}
|
|
|
|
|
2022-04-03 15:33:22 +09:00
|
|
|
if (ps.withFiles !== undefined) {
|
2019-04-07 21:50:36 +09:00
|
|
|
query.andWhere(ps.withFiles ? `note.fileIds != '{}'` : `note.fileIds = '{}'`);
|
|
|
|
}
|
2017-03-03 08:06:34 +09:00
|
|
|
|
2022-04-03 15:33:22 +09:00
|
|
|
if (ps.poll !== undefined) {
|
2019-04-07 21:50:36 +09:00
|
|
|
query.andWhere(ps.poll ? 'note.hasPoll = TRUE' : 'note.hasPoll = FALSE');
|
2017-03-04 04:28:38 +09:00
|
|
|
}
|
2017-03-03 08:06:34 +09:00
|
|
|
|
2018-03-17 03:33:36 +09:00
|
|
|
// TODO
|
|
|
|
//if (bot != undefined) {
|
2018-03-29 14:48:47 +09:00
|
|
|
// query.isBot = bot;
|
2018-03-17 03:33:36 +09:00
|
|
|
//}
|
|
|
|
|
2022-02-19 14:05:32 +09:00
|
|
|
const notes = await query.take(ps.limit).getMany();
|
2017-03-03 08:06:34 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
return await Notes.packMany(notes);
|
2019-02-22 11:46:58 +09:00
|
|
|
});
|