1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Fix video comments display with deleted comments

This commit is contained in:
Chocobozzz 2021-02-19 09:50:13 +01:00
parent fae6e4da8f
commit 9d6b9d10ef
No known key found for this signature in database
GPG key ID: 583A612D890159BE
11 changed files with 118 additions and 60 deletions

View file

@ -1,5 +1,5 @@
import * as express from 'express'
import { ResultList, UserRight } from '../../../../shared/models'
import { ResultList, ThreadsResultList, UserRight } from '../../../../shared/models'
import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model'
import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
import { getFormattedObjects } from '../../../helpers/utils'
@ -30,6 +30,7 @@ import {
import { AccountModel } from '../../../models/account/account'
import { VideoCommentModel } from '../../../models/video/video-comment'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { logger } from '@server/helpers/logger'
const auditLogger = auditLoggerFactory('comments')
const videoCommentRouter = express.Router()
@ -108,7 +109,7 @@ 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: ResultList<VideoCommentModel>
let resultList: ThreadsResultList<VideoCommentModel>
if (video.commentsEnabled === true) {
const apiOptions = await Hooks.wrapObject({
@ -128,11 +129,15 @@ async function listVideoThreads (req: express.Request, res: express.Response) {
} else {
resultList = {
total: 0,
totalNotDeletedComments: 0,
data: []
}
}
return res.json(getFormattedObjects(resultList.data, resultList.total))
return res.json({
...getFormattedObjects(resultList.data, resultList.total),
totalNotDeletedComments: resultList.totalNotDeletedComments
})
}
async function listVideoThreadComments (req: express.Request, res: express.Response) {
@ -161,6 +166,8 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo
}
}
logger.info('coucou', { resultList })
if (resultList.data.length === 0) {
return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
}