2022-06-14 09:01:23 +00:00
import { Notes } from '@/models/index.js' ;
2023-02-19 20:47:46 +00:00
import define from '@/server/api/define.js' ;
import { makePaginationQuery } from '@/server/api/common/make-pagination-query.js' ;
import { generateVisibilityQuery } from '@/server/api/common/generate-visibility-query.js' ;
import { generateMutedUserQuery } from '@/server/api/common/generate-muted-user-query.js' ;
import { generateBlockedUserQuery } from '@/server/api/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
2022-07-24 10:07:29 +00: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 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-12-13 17:36:54 +00:00
v2 : {
method : 'get' ,
alias : 'notes/:noteId/children' ,
2023-01-26 12:25:13 +00:00
pathParameters : [ 'noteId' ] ,
2022-12-13 17:36:54 +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' } ,
2022-07-24 10:07:29 +00: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 05:05:32 +00:00
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 )
2022-07-24 10:07:29 +00:00
. andWhere ( 'note.id IN (SELECT id FROM note_replies(:noteId, :depth, :limit))' , { noteId : ps.noteId , depth : ps.depth , limit : ps.limit } )
2022-12-26 08:09:11 +00:00
. innerJoinAndSelect ( 'note.user' , 'user' ) ;
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-07-24 10:07:29 +00:00
const notes = await query . getMany ( ) ;
2019-04-07 12:50:36 +00:00
2022-07-24 19:13:43 +00:00
return await Notes . packMany ( notes , user , { detail : false } ) ;
2019-03-07 04:03:46 +00:00
} ) ;