]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/activitypub/video-comments.ts
Cleanup shared models
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / activitypub / video-comments.ts
index 0415db21c27e7d5454ddfac568d59e87d7cc4736..ea852c4910a3ab43e9a0dce75ae9425bcb1eef97 100644 (file)
@@ -1,13 +1,22 @@
-import * as validator from 'validator'
-import { ACTIVITY_PUB, CONSTRAINTS_FIELDS } from '../../../initializers'
+import validator from 'validator'
+import { ACTIVITY_PUB } from '../../../initializers/constants'
 import { exists, isArray, isDateValid } from '../misc'
-import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
+import { isActivityPubUrlValid } from './misc'
 
 function sanitizeAndCheckVideoCommentObject (comment: any) {
-  if (!comment || comment.type !== 'Note') return false
+  if (!comment) return false
+
+  if (!isCommentTypeValid(comment)) return false
 
   normalizeComment(comment)
 
+  if (comment.type === 'Tombstone') {
+    return isActivityPubUrlValid(comment.id) &&
+      isDateValid(comment.published) &&
+      isDateValid(comment.deleted) &&
+      isActivityPubUrlValid(comment.url)
+  }
+
   return isActivityPubUrlValid(comment.id) &&
     isCommentContentValid(comment.content) &&
     isActivityPubUrlValid(comment.inReplyTo) &&
@@ -36,8 +45,15 @@ function normalizeComment (comment: any) {
   if (!comment) return
 
   if (typeof comment.url !== 'string') {
-    comment.url = comment.url.href || comment.url.url
+    if (typeof comment.url === 'object') comment.url = comment.url.href || comment.url.url
+    else comment.url = comment.id
   }
+}
+
+function isCommentTypeValid (comment: any): boolean {
+  if (comment.type === 'Note') return true
+
+  if (comment.type === 'Tombstone' && comment.formerType === 'Note') return true
 
-  return
+  return false
 }