Add ability to list comments on local videos
This commit is contained in:
parent
045224d5eb
commit
0e6cd1c00f
|
@ -54,6 +54,10 @@ export class VideoCommentListComponent extends RestTable implements OnInit {
|
||||||
{
|
{
|
||||||
value: 'local:false',
|
value: 'local:false',
|
||||||
label: $localize`Remote comments`
|
label: $localize`Remote comments`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'localVideo:true',
|
||||||
|
label: $localize`Comments on local videos`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,6 +190,10 @@ export class VideoCommentService {
|
||||||
prefix: 'local:',
|
prefix: 'local:',
|
||||||
isBoolean: true
|
isBoolean: true
|
||||||
},
|
},
|
||||||
|
onLocalVideo: {
|
||||||
|
prefix: 'localVideo:',
|
||||||
|
isBoolean: true
|
||||||
|
},
|
||||||
|
|
||||||
searchAccount: { prefix: 'account:' },
|
searchAccount: { prefix: 'account:' },
|
||||||
searchVideo: { prefix: 'video:' }
|
searchVideo: { prefix: 'video:' }
|
||||||
|
|
|
@ -91,6 +91,7 @@ async function listComments (req: express.Request, res: express.Response) {
|
||||||
sort: req.query.sort,
|
sort: req.query.sort,
|
||||||
|
|
||||||
isLocal: req.query.isLocal,
|
isLocal: req.query.isLocal,
|
||||||
|
onLocalVideo: req.query.onLocalVideo,
|
||||||
search: req.query.search,
|
search: req.query.search,
|
||||||
searchAccount: req.query.searchAccount,
|
searchAccount: req.query.searchAccount,
|
||||||
searchVideo: req.query.searchVideo
|
searchVideo: req.query.searchVideo
|
||||||
|
|
|
@ -24,6 +24,12 @@ const listVideoCommentsValidator = [
|
||||||
.custom(isBooleanValid)
|
.custom(isBooleanValid)
|
||||||
.withMessage('Should have a valid is local boolean'),
|
.withMessage('Should have a valid is local boolean'),
|
||||||
|
|
||||||
|
query('onLocalVideo')
|
||||||
|
.optional()
|
||||||
|
.customSanitizer(toBooleanOrNull)
|
||||||
|
.custom(isBooleanValid)
|
||||||
|
.withMessage('Should have a valid is on local video boolean'),
|
||||||
|
|
||||||
query('search')
|
query('search')
|
||||||
.optional()
|
.optional()
|
||||||
.custom(exists).withMessage('Should have a valid search'),
|
.custom(exists).withMessage('Should have a valid search'),
|
||||||
|
|
|
@ -14,6 +14,7 @@ import {
|
||||||
Table,
|
Table,
|
||||||
UpdatedAt
|
UpdatedAt
|
||||||
} from 'sequelize-typescript'
|
} from 'sequelize-typescript'
|
||||||
|
import { exists } from '@server/helpers/custom-validators/misc'
|
||||||
import { getServerActor } from '@server/models/application/application'
|
import { getServerActor } from '@server/models/application/application'
|
||||||
import { MAccount, MAccountId, MUserAccountId } from '@server/types/models'
|
import { MAccount, MAccountId, MUserAccountId } from '@server/types/models'
|
||||||
import { VideoPrivacy } from '@shared/models'
|
import { VideoPrivacy } from '@shared/models'
|
||||||
|
@ -312,12 +313,13 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
|
||||||
count: number
|
count: number
|
||||||
sort: string
|
sort: string
|
||||||
|
|
||||||
|
onLocalVideo?: boolean
|
||||||
isLocal?: boolean
|
isLocal?: boolean
|
||||||
search?: string
|
search?: string
|
||||||
searchAccount?: string
|
searchAccount?: string
|
||||||
searchVideo?: string
|
searchVideo?: string
|
||||||
}) {
|
}) {
|
||||||
const { start, count, sort, isLocal, search, searchAccount, searchVideo } = parameters
|
const { start, count, sort, isLocal, search, searchAccount, searchVideo, onLocalVideo } = parameters
|
||||||
|
|
||||||
const where: WhereOptions = {
|
const where: WhereOptions = {
|
||||||
deletedAt: null
|
deletedAt: null
|
||||||
|
@ -363,6 +365,10 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
|
||||||
Object.assign(whereVideo, searchAttribute(searchVideo, 'name'))
|
Object.assign(whereVideo, searchAttribute(searchVideo, 'name'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exists(onLocalVideo)) {
|
||||||
|
Object.assign(whereVideo, { remote: !onLocalVideo })
|
||||||
|
}
|
||||||
|
|
||||||
const getQuery = (forCount: boolean) => {
|
const getQuery = (forCount: boolean) => {
|
||||||
return {
|
return {
|
||||||
offset: start,
|
offset: start,
|
||||||
|
|
|
@ -254,6 +254,22 @@ describe('Test video comments', function () {
|
||||||
expect(total).to.equal(0)
|
expect(total).to.equal(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should filter instance comments by onLocalVideo', async function () {
|
||||||
|
{
|
||||||
|
const { total, data } = await command.listForAdmin({ onLocalVideo: false })
|
||||||
|
|
||||||
|
expect(data).to.have.lengthOf(0)
|
||||||
|
expect(total).to.equal(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const { total, data } = await command.listForAdmin({ onLocalVideo: true })
|
||||||
|
|
||||||
|
expect(data).to.not.have.lengthOf(0)
|
||||||
|
expect(total).to.not.equal(0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it('Should search instance comments by account', async function () {
|
it('Should search instance comments by account', async function () {
|
||||||
const { total, data } = await command.listForAdmin({ searchAccount: 'user' })
|
const { total, data } = await command.listForAdmin({ searchAccount: 'user' })
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ export class CommentsCommand extends AbstractCommand {
|
||||||
count?: number
|
count?: number
|
||||||
sort?: string
|
sort?: string
|
||||||
isLocal?: boolean
|
isLocal?: boolean
|
||||||
|
onLocalVideo?: boolean
|
||||||
search?: string
|
search?: string
|
||||||
searchAccount?: string
|
searchAccount?: string
|
||||||
searchVideo?: string
|
searchVideo?: string
|
||||||
|
@ -21,7 +22,7 @@ export class CommentsCommand extends AbstractCommand {
|
||||||
const { sort = '-createdAt' } = options
|
const { sort = '-createdAt' } = options
|
||||||
const path = '/api/v1/videos/comments'
|
const path = '/api/v1/videos/comments'
|
||||||
|
|
||||||
const query = { sort, ...pick(options, [ 'start', 'count', 'isLocal', 'search', 'searchAccount', 'searchVideo' ]) }
|
const query = { sort, ...pick(options, [ 'start', 'count', 'isLocal', 'onLocalVideo', 'search', 'searchAccount', 'searchVideo' ]) }
|
||||||
|
|
||||||
return this.getRequestBody<ResultList<VideoComment>>({
|
return this.getRequestBody<ResultList<VideoComment>>({
|
||||||
...options,
|
...options,
|
||||||
|
|
Loading…
Reference in New Issue