]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-delete.ts
Fix user notifications on new follow
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-delete.ts
index 038d8c4d30dcadde3bb2d5d2a187afe4f077f815..845a7b249a3384b9aa9988ebe2a60224f923a5b4 100644 (file)
@@ -7,9 +7,13 @@ import { ActorModel } from '../../../models/activitypub/actor'
 import { VideoModel } from '../../../models/video/video'
 import { VideoChannelModel } from '../../../models/video/video-channel'
 import { VideoCommentModel } from '../../../models/video/video-comment'
-import { forwardActivity } from '../send/utils'
+import { forwardVideoRelatedActivity } from '../send/utils'
+import { VideoPlaylistModel } from '../../../models/video/video-playlist'
+import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
+
+async function processDeleteActivity (options: APProcessorOptions<ActivityDelete>) {
+  const { activity, byActor } = options
 
-async function processDeleteActivity (activity: ActivityDelete, byActor: ActorModel) {
   const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id
 
   if (activity.actor === objectUrl) {
@@ -45,6 +49,15 @@ async function processDeleteActivity (activity: ActivityDelete, byActor: ActorMo
     }
   }
 
+  {
+    const videoPlaylist = await VideoPlaylistModel.loadByUrlAndPopulateAccount(objectUrl)
+    if (videoPlaylist) {
+      if (videoPlaylist.isOwned()) throw new Error(`Remote instance cannot delete owned playlist ${videoPlaylist.url}.`)
+
+      return retryTransactionWrapper(processDeleteVideoPlaylist, byActor, videoPlaylist)
+    }
+  }
+
   return undefined
 }
 
@@ -70,24 +83,38 @@ async function processDeleteVideo (actor: ActorModel, videoToDelete: VideoModel)
   logger.info('Remote video with uuid %s removed.', videoToDelete.uuid)
 }
 
+async function processDeleteVideoPlaylist (actor: ActorModel, playlistToDelete: VideoPlaylistModel) {
+  logger.debug('Removing remote video playlist "%s".', playlistToDelete.uuid)
+
+  await sequelizeTypescript.transaction(async t => {
+    if (playlistToDelete.OwnerAccount.Actor.id !== actor.id) {
+      throw new Error('Account ' + actor.url + ' does not own video playlist ' + playlistToDelete.url)
+    }
+
+    await playlistToDelete.destroy({ transaction: t })
+  })
+
+  logger.info('Remote video playlist with uuid %s removed.', playlistToDelete.uuid)
+}
+
 async function processDeleteAccount (accountToRemove: AccountModel) {
-  logger.debug('Removing remote account "%s".', accountToRemove.Actor.uuid)
+  logger.debug('Removing remote account "%s".', accountToRemove.Actor.url)
 
   await sequelizeTypescript.transaction(async t => {
     await accountToRemove.destroy({ transaction: t })
   })
 
-  logger.info('Remote account with uuid %s removed.', accountToRemove.Actor.uuid)
+  logger.info('Remote account %s removed.', accountToRemove.Actor.url)
 }
 
 async function processDeleteVideoChannel (videoChannelToRemove: VideoChannelModel) {
-  logger.debug('Removing remote video channel "%s".', videoChannelToRemove.Actor.uuid)
+  logger.debug('Removing remote video channel "%s".', videoChannelToRemove.Actor.url)
 
   await sequelizeTypescript.transaction(async t => {
     await videoChannelToRemove.destroy({ transaction: t })
   })
 
-  logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.Actor.uuid)
+  logger.info('Remote video channel %s removed.', videoChannelToRemove.Actor.url)
 }
 
 function processDeleteVideoComment (byActor: ActorModel, videoComment: VideoCommentModel, activity: ActivityDelete) {
@@ -103,7 +130,7 @@ function processDeleteVideoComment (byActor: ActorModel, videoComment: VideoComm
     if (videoComment.Video.isOwned()) {
       // Don't resend the activity to the sender
       const exceptions = [ byActor ]
-      await forwardActivity(activity, t, exceptions)
+      await forwardVideoRelatedActivity(activity, t, exceptions, videoComment.Video)
     }
 
     logger.info('Remote video comment %s removed.', videoComment.url)