-import { getOrCreateActorAndServerAndModel } from '../actor'
-
-async function processDeleteActivity (activity: ActivityDelete) {
- const actor = await getOrCreateActorAndServerAndModel(activity.actor)
-
- 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.')
-
- 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.')
-
- return processDeleteVideoChannel(actor.VideoChannel)
+import { VideoPlaylistModel } from '../../../models/video/video-playlist'
+import { APProcessorOptions } from '../../../types/activitypub-processor.model'
+import {
+ MAccountActor,
+ MActor,
+ MActorFull,
+ MActorSignature,
+ MChannelAccountActor,
+ MChannelActor,
+ MCommentOwnerVideo
+} from '../../../types/models'
+import { forwardVideoRelatedActivity } from '../send/utils'
+
+async function processDeleteActivity (options: APProcessorOptions<ActivityDelete>) {
+ const { activity, byActor } = options
+
+ const objectUrl = typeof activity.object === 'string' ? activity.object : activity.object.id
+
+ if (activity.actor === objectUrl) {
+ // We need more attributes (all the account and channel)
+ const byActorFull = await ActorModel.loadByUrlAndPopulateAccountAndChannel(byActor.url)
+
+ if (byActorFull.type === 'Person') {
+ if (!byActorFull.Account) throw new Error('Actor ' + byActorFull.url + ' is a person but we cannot find it in database.')
+
+ const accountToDelete = byActorFull.Account as MAccountActor
+ accountToDelete.Actor = byActorFull
+
+ return retryTransactionWrapper(processDeleteAccount, accountToDelete)
+ } 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 MChannelAccountActor & { Actor: MActorFull }
+ channelToDelete.Actor = byActorFull
+ return retryTransactionWrapper(processDeleteVideoChannel, channelToDelete)