2020-08-18 13:44:21 +00:00
|
|
|
import $ from 'cafy';
|
2021-03-23 08:43:07 +00:00
|
|
|
import { ID } from '@/misc/cafy-id';
|
2020-08-18 13:44:21 +00:00
|
|
|
import define from '../../define';
|
|
|
|
import { ApiError } from '../../error';
|
|
|
|
import { Notes, Channels } from '../../../../models';
|
|
|
|
import { makePaginationQuery } from '../../common/make-pagination-query';
|
|
|
|
import { activeUsersChart } from '../../../../services/chart';
|
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['notes', 'channels'],
|
|
|
|
|
|
|
|
requireCredential: false as const,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
channelId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
},
|
|
|
|
|
|
|
|
limit: {
|
|
|
|
validator: $.optional.num.range(1, 100),
|
|
|
|
default: 10,
|
|
|
|
},
|
|
|
|
|
|
|
|
sinceId: {
|
|
|
|
validator: $.optional.type(ID),
|
|
|
|
},
|
|
|
|
|
|
|
|
untilId: {
|
|
|
|
validator: $.optional.type(ID),
|
|
|
|
},
|
|
|
|
|
|
|
|
sinceDate: {
|
|
|
|
validator: $.optional.num,
|
|
|
|
},
|
|
|
|
|
|
|
|
untilDate: {
|
|
|
|
validator: $.optional.num,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
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,
|
|
|
|
ref: 'Note',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchChannel: {
|
|
|
|
message: 'No such channel.',
|
|
|
|
code: 'NO_SUCH_CHANNEL',
|
|
|
|
id: '4d0eeeba-a02c-4c3c-9966-ef60d38d2e7f'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default define(meta, async (ps, user) => {
|
|
|
|
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
|
|
|
|
|
|
|
|
const timeline = await query.take(ps.limit!).getMany();
|
|
|
|
|
2021-03-24 02:05:37 +00:00
|
|
|
if (user) activeUsersChart.update(user);
|
2020-08-18 13:44:21 +00:00
|
|
|
|
|
|
|
return await Notes.packMany(timeline, user);
|
|
|
|
});
|