2017-12-22 09:14:50 +01:00
|
|
|
import * as validator from 'validator'
|
2018-01-26 11:20:46 +01:00
|
|
|
import { ACTIVITY_PUB } from '../../../initializers'
|
|
|
|
import { exists, isArray, isDateValid } from '../misc'
|
2017-12-22 09:14:50 +01:00
|
|
|
import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
|
|
|
|
|
|
|
|
function isVideoCommentCreateActivityValid (activity: any) {
|
|
|
|
return isBaseActivityValid(activity, 'Create') &&
|
|
|
|
isVideoCommentObjectValid(activity.object)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVideoCommentObjectValid (comment: any) {
|
|
|
|
return comment.type === 'Note' &&
|
|
|
|
isActivityPubUrlValid(comment.id) &&
|
|
|
|
isCommentContentValid(comment.content) &&
|
|
|
|
isActivityPubUrlValid(comment.inReplyTo) &&
|
|
|
|
isDateValid(comment.published) &&
|
2018-01-26 11:20:46 +01:00
|
|
|
isActivityPubUrlValid(comment.url) &&
|
|
|
|
isArray(comment.to) &&
|
|
|
|
comment.to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 // Only accept public comments
|
2017-12-22 09:14:50 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 11:19:16 +01:00
|
|
|
function isVideoCommentDeleteActivityValid (activity: any) {
|
|
|
|
return isBaseActivityValid(activity, 'Delete')
|
|
|
|
}
|
|
|
|
|
2017-12-22 09:14:50 +01:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2018-01-04 11:19:16 +01:00
|
|
|
isVideoCommentCreateActivityValid,
|
2018-01-10 17:18:12 +01:00
|
|
|
isVideoCommentDeleteActivityValid,
|
|
|
|
isVideoCommentObjectValid
|
2017-12-22 09:14:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function isCommentContentValid (content: any) {
|
|
|
|
return exists(content) && validator.isLength('' + content, { min: 1 })
|
|
|
|
}
|