2022-06-14 11:01:23 +02:00
import { Brackets } from 'typeorm' ;
import { Notes } from '@/models/index.js' ;
2022-02-27 03:07:39 +01: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 05:03:46 +01:00
export const meta = {
tags : [ 'notes' ] ,
2022-01-18 14:27:10 +01:00
requireCredential : false ,
2021-07-20 20:51:59 +02:00
requireCredentialPrivateMode : true ,
2019-03-07 05:03:46 +01:00
2022-07-24 12:07:29 +02:00
description : 'Get a list of children of a notes. Children includes replies as well as quote renotes that quote the respective post. A post will not be duplicated if it is a reply and a quote of a note in this thread. For depths larger than 1 the threading has to be computed by the client.' ,
2019-03-07 05:03:46 +01:00
res : {
2022-01-18 14:27:10 +01:00
type : 'array' ,
optional : false , nullable : false ,
2019-03-07 05:03:46 +01:00
items : {
2022-01-18 14:27:10 +01:00
type : 'object' ,
optional : false , nullable : false ,
2019-04-23 15:35:26 +02:00
ref : 'Note' ,
2021-12-09 15:58:30 +01:00
} ,
2019-03-07 05:03:46 +01:00
} ,
2021-07-20 20:51:59 +02:00
} ;
2019-03-07 05:03:46 +01:00
2022-02-20 05:15:40 +01:00
export const paramDef = {
2022-02-19 06:05:32 +01:00
type : 'object' ,
properties : {
noteId : { type : 'string' , format : 'misskey:id' } ,
2022-07-24 12:07:29 +02:00
limit : {
description : 'The maximum number of replies/quotes to show per parent note, i.e. the maximum number of children each note may have.' ,
type : 'integer' ,
minimum : 1 ,
maximum : 100 ,
default : 10 ,
} ,
depth : {
description : 'The number of layers of replies to fetch at once. Defaults to 1 for backward compatibility.' ,
type : 'integer' ,
minimum : 1 ,
maximum : 100 ,
default : 1 ,
} ,
2022-02-19 06:05:32 +01:00
sinceId : { type : 'string' , format : 'misskey:id' } ,
untilId : { type : 'string' , format : 'misskey:id' } ,
} ,
required : [ 'noteId' ] ,
} as const ;
2022-01-02 18:12:50 +01:00
// eslint-disable-next-line import/no-default-export
2022-02-19 06:05:32 +01:00
export default define ( meta , paramDef , async ( ps , user ) = > {
2019-04-07 14:50:36 +02:00
const query = makePaginationQuery ( Notes . createQueryBuilder ( 'note' ) , ps . sinceId , ps . untilId )
2022-07-24 12:07:29 +02:00
. andWhere ( 'note.id IN (SELECT id FROM note_replies(:noteId, :depth, :limit))' , { noteId : ps.noteId , depth : ps.depth , limit : ps.limit } )
2021-03-21 04:33:37 +01:00
. innerJoinAndSelect ( 'note.user' , 'user' )
2022-02-27 05:59:10 +01:00
. leftJoinAndSelect ( 'user.avatar' , 'avatar' )
. leftJoinAndSelect ( 'user.banner' , 'banner' )
2019-04-07 14:50:36 +02:00
2019-12-11 16:49:30 +01:00
generateVisibilityQuery ( query , user ) ;
2022-06-25 07:23:59 +02:00
if ( user ) {
generateMutedUserQuery ( query , user ) ;
generateBlockedUserQuery ( query , user ) ;
}
2019-04-07 14:50:36 +02:00
2022-07-24 12:07:29 +02:00
const notes = await query . getMany ( ) ;
2019-04-07 14:50:36 +02:00
2022-07-24 21:13:43 +02:00
return await Notes . packMany ( notes , user , { detail : false } ) ;
2019-03-07 05:03:46 +01:00
} ) ;