Revert "Delete actor too when deleting account/video channel"
[oweals/peertube.git] / server / models / activitypub / actor.ts
index f231dba742df7d940a46cf48ff49f63383057021..267032e2ab7e6ff9058a7025e34f432fe0a5c508 100644 (file)
@@ -3,7 +3,6 @@ import { extname } from 'path'
 import * as Sequelize from 'sequelize'
 import {
   AllowNull,
-  BeforeDestroy,
   BelongsTo,
   Column,
   CreatedAt,
@@ -38,8 +37,6 @@ import { ServerModel } from '../server/server'
 import { throwIfNotValid } from '../utils'
 import { VideoChannelModel } from '../video/video-channel'
 import { ActorFollowModel } from './actor-follow'
-import { logger } from '../../helpers/logger'
-import { sendDeleteActor } from '../../lib/activitypub/send'
 
 enum ScopeNames {
   FULL = 'FULL'
@@ -227,28 +224,22 @@ export class ActorModel extends Model<ActorModel> {
 
   @HasOne(() => AccountModel, {
     foreignKey: {
-      allowNull: false
-    }
+      allowNull: true
+    },
+    onDelete: 'cascade',
+    hooks: true
   })
   Account: AccountModel
 
   @HasOne(() => VideoChannelModel, {
     foreignKey: {
-      allowNull: false
-    }
+      allowNull: true
+    },
+    onDelete: 'cascade',
+    hooks: true
   })
   VideoChannel: VideoChannelModel
 
-  @BeforeDestroy
-  static async sendDeleteIfOwned (instance: ActorModel, options) {
-    if (instance.isOwned()) {
-      logger.debug('Sending delete of actor %s.', instance.url)
-      return sendDeleteActor(instance, options.transaction)
-    }
-
-    return undefined
-  }
-
   static load (id: number) {
     return ActorModel.unscoped().findById(id)
   }