aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/account.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account/account.ts')
-rw-r--r--server/models/account/account.ts26
1 files changed, 21 insertions, 5 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index f81c50180..20724ae0c 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -1,9 +1,10 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { 2import {
3 AfterDestroy, AllowNull, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Model, Table, 3 AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Model, Table,
4 UpdatedAt 4 UpdatedAt
5} from 'sequelize-typescript' 5} from 'sequelize-typescript'
6import { Account } from '../../../shared/models/actors' 6import { Account } from '../../../shared/models/actors'
7import { logger } from '../../helpers/logger'
7import { sendDeleteActor } from '../../lib/activitypub/send' 8import { sendDeleteActor } from '../../lib/activitypub/send'
8import { ActorModel } from '../activitypub/actor' 9import { ActorModel } from '../activitypub/actor'
9import { ApplicationModel } from '../application/application' 10import { ApplicationModel } from '../application/application'
@@ -11,6 +12,7 @@ import { AvatarModel } from '../avatar/avatar'
11import { ServerModel } from '../server/server' 12import { ServerModel } from '../server/server'
12import { getSort } from '../utils' 13import { getSort } from '../utils'
13import { VideoChannelModel } from '../video/video-channel' 14import { VideoChannelModel } from '../video/video-channel'
15import { VideoCommentModel } from '../video/video-comment'
14import { UserModel } from './user' 16import { UserModel } from './user'
15 17
16@DefaultScope({ 18@DefaultScope({
@@ -80,7 +82,7 @@ export class AccountModel extends Model<AccountModel> {
80 }, 82 },
81 onDelete: 'cascade' 83 onDelete: 'cascade'
82 }) 84 })
83 Account: ApplicationModel 85 Application: ApplicationModel
84 86
85 @HasMany(() => VideoChannelModel, { 87 @HasMany(() => VideoChannelModel, {
86 foreignKey: { 88 foreignKey: {
@@ -91,10 +93,24 @@ export class AccountModel extends Model<AccountModel> {
91 }) 93 })
92 VideoChannels: VideoChannelModel[] 94 VideoChannels: VideoChannelModel[]
93 95
94 @AfterDestroy 96 @HasMany(() => VideoCommentModel, {
95 static sendDeleteIfOwned (instance: AccountModel) { 97 foreignKey: {
98 allowNull: false
99 },
100 onDelete: 'cascade',
101 hooks: true
102 })
103 VideoComments: VideoCommentModel[]
104
105 @BeforeDestroy
106 static async sendDeleteIfOwned (instance: AccountModel, options) {
107 if (!instance.Actor) {
108 instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel
109 }
110
96 if (instance.isOwned()) { 111 if (instance.isOwned()) {
97 return sendDeleteActor(instance.Actor, undefined) 112 logger.debug('Sending delete of actor of account %s.', instance.Actor.url)
113 return sendDeleteActor(instance.Actor, options.transaction)
98 } 114 }
99 115
100 return undefined 116 return undefined