-async function listVideoThreadComments (req: express.Request, res: express.Response, next: express.NextFunction) {
- const resultList = await VideoCommentModel.listThreadCommentsForApi(res.locals.video.id, res.locals.videoCommentThread.id)
+async function listVideoThreads (req: express.Request, res: express.Response) {
+ const video = res.locals.onlyVideo
+ const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
+
+ let resultList: ThreadsResultList<VideoCommentModel>
+
+ if (video.commentsEnabled === true) {
+ const apiOptions = await Hooks.wrapObject({
+ videoId: video.id,
+ isVideoOwned: video.isOwned(),
+ start: req.query.start,
+ count: req.query.count,
+ sort: req.query.sort,
+ user
+ }, 'filter:api.video-threads.list.params')
+
+ resultList = await Hooks.wrapPromiseFun(
+ VideoCommentModel.listThreadsForApi,
+ apiOptions,
+ 'filter:api.video-threads.list.result'
+ )
+ } else {
+ resultList = {
+ total: 0,
+ totalNotDeletedComments: 0,
+ data: []
+ }
+ }