2022-02-27 02:07:39 +00:00
|
|
|
import define from '../../define.js';
|
|
|
|
import { ApiError } from '../../error.js';
|
|
|
|
import { Notes, Channels } from '@/models/index.js';
|
|
|
|
import { makePaginationQuery } from '../../common/make-pagination-query.js';
|
|
|
|
import { activeUsersChart } from '@/services/chart/index.js';
|
2020-08-18 13:44:21 +00:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['notes', 'channels'],
|
|
|
|
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: false,
|
2020-08-18 13:44:21 +00:00
|
|
|
|
|
|
|
res: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2020-08-18 13:44:21 +00:00
|
|
|
items: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2020-08-18 13:44:21 +00:00
|
|
|
ref: 'Note',
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2020-08-18 13:44:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchChannel: {
|
|
|
|
message: 'No such channel.',
|
|
|
|
code: 'NO_SUCH_CHANNEL',
|
2021-12-09 14:58:30 +00:00
|
|
|
id: '4d0eeeba-a02c-4c3c-9966-ef60d38d2e7f',
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2020-08-18 13:44:21 +00:00
|
|
|
|
2022-02-20 04:15:40 +00:00
|
|
|
export const paramDef = {
|
2022-02-19 05:05:32 +00:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
channelId: { 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' },
|
|
|
|
sinceDate: { type: 'integer' },
|
|
|
|
untilDate: { type: 'integer' },
|
|
|
|
},
|
|
|
|
required: ['channelId'],
|
|
|
|
} 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) => {
|
2020-08-18 13:44:21 +00:00
|
|
|
const channel = await Channels.findOne({
|
|
|
|
id: ps.channelId,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (channel == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
//#region Construct query
|
2021-02-20 13:28:53 +00:00
|
|
|
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
|
2020-08-18 13:44:21 +00:00
|
|
|
.andWhere('note.channelId = :channelId', { channelId: channel.id })
|
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-08-18 13:44:21 +00:00
|
|
|
.leftJoinAndSelect('note.channel', 'channel');
|
|
|
|
//#endregion
|
|
|
|
|
2022-02-19 05:05:32 +00:00
|
|
|
const timeline = await query.take(ps.limit).getMany();
|
2020-08-18 13:44:21 +00:00
|
|
|
|
2022-02-08 18:46:58 +00:00
|
|
|
if (user) activeUsersChart.read(user);
|
2020-08-18 13:44:21 +00:00
|
|
|
|
|
|
|
return await Notes.packMany(timeline, user);
|
|
|
|
});
|