848f499def
For now we Create these activities, but we should just send them directly. This fix handles correctly direct Dislikes/Flags/Views, we'll implement the sending correctly these activities in the next peertube version
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import * as validator from 'validator'
|
|
import { ACTIVITY_PUB, CONSTRAINTS_FIELDS } from '../../../initializers'
|
|
import { exists, isArray, isDateValid } from '../misc'
|
|
import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
|
|
|
|
function sanitizeAndCheckVideoCommentObject (comment: any) {
|
|
if (!comment || comment.type !== 'Note') return false
|
|
|
|
normalizeComment(comment)
|
|
|
|
return isActivityPubUrlValid(comment.id) &&
|
|
isCommentContentValid(comment.content) &&
|
|
isActivityPubUrlValid(comment.inReplyTo) &&
|
|
isDateValid(comment.published) &&
|
|
isActivityPubUrlValid(comment.url) &&
|
|
isArray(comment.to) &&
|
|
(
|
|
comment.to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ||
|
|
comment.cc.indexOf(ACTIVITY_PUB.PUBLIC) !== -1
|
|
) // Only accept public comments
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export {
|
|
sanitizeAndCheckVideoCommentObject
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function isCommentContentValid (content: any) {
|
|
return exists(content) && validator.isLength('' + content, { min: 1 })
|
|
}
|
|
|
|
function normalizeComment (comment: any) {
|
|
if (!comment) return
|
|
|
|
if (typeof comment.url !== 'string') {
|
|
comment.url = comment.url.href || comment.url.url
|
|
}
|
|
|
|
return
|
|
}
|