Fix delete activities
authorChocobozzz <me@florianbigard.com>
Thu, 4 Jan 2018 15:56:36 +0000 (16:56 +0100)
committerChocobozzz <me@florianbigard.com>
Thu, 4 Jan 2018 15:56:36 +0000 (16:56 +0100)
server/lib/activitypub/process/process-delete.ts
server/lib/activitypub/send/send-delete.ts
server/lib/activitypub/url.ts
shared/models/activitypub/activity.ts

index 604570e74808e56dc8948377a3cd13e94273028d..01751422d3db72a1a45c216d0667708c4d9f8c9d 100644 (file)
@@ -12,7 +12,7 @@ import { getOrCreateActorAndServerAndModel } from '../actor'
 async function processDeleteActivity (activity: ActivityDelete) {
   const actor = await getOrCreateActorAndServerAndModel(activity.actor)
 
-  if (actor.url === activity.id) {
+  if (actor.url === activity.object) {
     if (actor.type === 'Person') {
       if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.')
 
@@ -25,14 +25,14 @@ async function processDeleteActivity (activity: ActivityDelete) {
   }
 
   {
-    const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(activity.id)
+    const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(activity.object)
     if (videoCommentInstance) {
       return processDeleteVideoComment(actor, videoCommentInstance)
     }
   }
 
   {
-    const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(activity.id)
+    const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(activity.object)
     if (videoInstance) {
       return processDeleteVideo(actor, videoInstance)
     }
index 1ca03189802ea138f91f358d338a47bc55514e96..995a534a637da979583b4130732fe314a031bc87 100644 (file)
@@ -4,12 +4,14 @@ import { ActorModel } from '../../../models/activitypub/actor'
 import { VideoModel } from '../../../models/video/video'
 import { VideoCommentModel } from '../../../models/video/video-comment'
 import { VideoShareModel } from '../../../models/video/video-share'
+import { getDeleteActivityPubUrl } from '../url'
 import { broadcastToFollowers } from './misc'
 
 async function sendDeleteVideo (video: VideoModel, t: Transaction) {
+  const url = getDeleteActivityPubUrl(video.url)
   const byActor = video.VideoChannel.Account.Actor
 
-  const data = deleteActivityData(video.url, byActor)
+  const data = deleteActivityData(url, video.url, byActor)
 
   const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
   actorsInvolved.push(byActor)
@@ -18,15 +20,17 @@ async function sendDeleteVideo (video: VideoModel, t: Transaction) {
 }
 
 async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
-  const data = deleteActivityData(byActor.url, byActor)
+  const url = getDeleteActivityPubUrl(byActor.url)
+  const data = deleteActivityData(url, byActor.url, byActor)
 
   return broadcastToFollowers(data, byActor, [ byActor ], t)
 }
 
 async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
-  const byActor = videoComment.Account.Actor
+  const url = getDeleteActivityPubUrl(videoComment.url)
 
-  const data = deleteActivityData(videoComment.url, byActor)
+  const byActor = videoComment.Account.Actor
+  const data = deleteActivityData(url, videoComment.url, byActor)
 
   const actorsInvolved = await VideoShareModel.loadActorsByShare(videoComment.Video.id, t)
   actorsInvolved.push(videoComment.Video.VideoChannel.Account.Actor)
@@ -45,10 +49,11 @@ export {
 
 // ---------------------------------------------------------------------------
 
-function deleteActivityData (url: string, byActor: ActorModel): ActivityDelete {
+function deleteActivityData (url: string, object: string, byActor: ActorModel): ActivityDelete {
   return {
     type: 'Delete',
     id: url,
-    actor: byActor.url
+    actor: byActor.url,
+    object
   }
 }
index 0d76922e043244aec73c40a929d12439713298a6..5705afbd62ff8ebdbe938439fe406205b47ad216 100644 (file)
@@ -55,6 +55,10 @@ function getAnnounceActivityPubUrl (originalUrl: string, byActor: ActorModel) {
   return originalUrl + '/announces/' + byActor.id
 }
 
+function getDeleteActivityPubUrl (originalUrl: string) {
+  return originalUrl + '/delete'
+}
+
 function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
   return originalUrl + '/updates/' + updatedAt
 }
@@ -76,5 +80,6 @@ export {
   getVideoViewActivityPubUrl,
   getVideoLikeActivityPubUrl,
   getVideoDislikeActivityPubUrl,
-  getVideoCommentActivityPubUrl
+  getVideoCommentActivityPubUrl,
+  getDeleteActivityPubUrl
 }
index a87afc54803b59e771375df5360714d38bf08fe7..56f7103bfcd9a858866355a847bceefc87a5aefc 100644 (file)
@@ -39,6 +39,7 @@ export interface ActivityUpdate extends BaseActivity {
 
 export interface ActivityDelete extends BaseActivity {
   type: 'Delete'
+  object: string
 }
 
 export interface ActivityFollow extends BaseActivity {