]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-delete.ts
Add context on activitypub responses
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-delete.ts
index 604570e74808e56dc8948377a3cd13e94273028d..03eadcbfc95d298dab9530dc7848c327672d30ab 100644 (file)
@@ -10,29 +10,35 @@ import { VideoCommentModel } from '../../../models/video/video-comment'
 import { getOrCreateActorAndServerAndModel } from '../actor'
 
 async function processDeleteActivity (activity: ActivityDelete) {
-  const actor = await getOrCreateActorAndServerAndModel(activity.actor)
+  const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id
+
+  if (activity.actor === objectUrl) {
+    let actor = await ActorModel.loadByUrl(activity.actor)
+    if (!actor) return
 
-  if (actor.url === activity.id) {
     if (actor.type === 'Person') {
       if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.')
 
+      actor.Account.Actor = await actor.Account.$get('Actor') as ActorModel
       return processDeleteAccount(actor.Account)
     } else if (actor.type === 'Group') {
       if (!actor.VideoChannel) throw new Error('Actor ' + actor.url + ' is a group but we cannot find it in database.')
 
+      actor.VideoChannel.Actor = await actor.VideoChannel.$get('Actor') as ActorModel
       return processDeleteVideoChannel(actor.VideoChannel)
     }
   }
 
+  const actor = await getOrCreateActorAndServerAndModel(activity.actor)
   {
-    const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(activity.id)
+    const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(objectUrl)
     if (videoCommentInstance) {
       return processDeleteVideoComment(actor, videoCommentInstance)
     }
   }
 
   {
-    const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(activity.id)
+    const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(objectUrl)
     if (videoInstance) {
       return processDeleteVideo(actor, videoInstance)
     }