]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-delete.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-delete.ts
index 79d0e0d79424901d8226f7a3b9ba8ab664b92cc2..ac0e7e235aaeb4e116188c06c662448bbd1fe008 100644 (file)
@@ -1,14 +1,22 @@
 import { ActivityDelete } from '../../../../shared/models/activitypub'
 import { retryTransactionWrapper } from '../../../helpers/database-utils'
 import { logger } from '../../../helpers/logger'
-import { sequelizeTypescript } from '../../../initializers'
-import { ActorModel } from '../../../models/activitypub/actor'
+import { sequelizeTypescript } from '../../../initializers/database'
+import { ActorModel } from '../../../models/actor/actor'
 import { VideoModel } from '../../../models/video/video'
 import { VideoCommentModel } from '../../../models/video/video-comment'
-import { forwardVideoRelatedActivity } from '../send/utils'
 import { VideoPlaylistModel } from '../../../models/video/video-playlist'
-import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
-import { MAccountActor, MActor, MActorSignature, MChannelActor, MChannelActorAccountActor } from '../../../typings/models'
+import { APProcessorOptions } from '../../../types/activitypub-processor.model'
+import {
+  MAccountActor,
+  MActor,
+  MActorFull,
+  MActorSignature,
+  MChannelAccountActor,
+  MChannelActor,
+  MCommentOwnerVideo
+} from '../../../types/models'
+import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
 
 async function processDeleteActivity (options: APProcessorOptions<ActivityDelete>) {
   const { activity, byActor } = options
@@ -29,9 +37,8 @@ async function processDeleteActivity (options: APProcessorOptions<ActivityDelete
     } else if (byActorFull.type === 'Group') {
       if (!byActorFull.VideoChannel) throw new Error('Actor ' + byActorFull.url + ' is a group but we cannot find it in database.')
 
-      const channelToDelete = byActorFull.VideoChannel as MChannelActorAccountActor
+      const channelToDelete = byActorFull.VideoChannel as MChannelAccountActor & { Actor: MActorFull }
       channelToDelete.Actor = byActorFull
-
       return retryTransactionWrapper(processDeleteVideoChannel, channelToDelete)
     }
   }
@@ -120,7 +127,10 @@ async function processDeleteVideoChannel (videoChannelToRemove: MChannelActor) {
   logger.info('Remote video channel %s removed.', videoChannelToRemove.Actor.url)
 }
 
-function processDeleteVideoComment (byActor: MActorSignature, videoComment: VideoCommentModel, activity: ActivityDelete) {
+function processDeleteVideoComment (byActor: MActorSignature, videoComment: MCommentOwnerVideo, activity: ActivityDelete) {
+  // Already deleted
+  if (videoComment.isDeleted()) return Promise.resolve()
+
   logger.debug('Removing remote video comment "%s".', videoComment.url)
 
   return sequelizeTypescript.transaction(async t => {
@@ -128,7 +138,9 @@ function processDeleteVideoComment (byActor: MActorSignature, videoComment: Vide
       throw new Error(`Account ${byActor.url} does not own video comment ${videoComment.url} or video ${videoComment.Video.url}`)
     }
 
-    await videoComment.destroy({ transaction: t })
+    videoComment.markAsDeleted()
+
+    await videoComment.save({ transaction: t })
 
     if (videoComment.Video.isOwned()) {
       // Don't resend the activity to the sender