diff options
Diffstat (limited to 'server/models/account/account.ts')
-rw-r--r-- | server/models/account/account.ts | 26 |
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 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { | 2 | import { |
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' |
6 | import { Account } from '../../../shared/models/actors' | 6 | import { Account } from '../../../shared/models/actors' |
7 | import { logger } from '../../helpers/logger' | ||
7 | import { sendDeleteActor } from '../../lib/activitypub/send' | 8 | import { sendDeleteActor } from '../../lib/activitypub/send' |
8 | import { ActorModel } from '../activitypub/actor' | 9 | import { ActorModel } from '../activitypub/actor' |
9 | import { ApplicationModel } from '../application/application' | 10 | import { ApplicationModel } from '../application/application' |
@@ -11,6 +12,7 @@ import { AvatarModel } from '../avatar/avatar' | |||
11 | import { ServerModel } from '../server/server' | 12 | import { ServerModel } from '../server/server' |
12 | import { getSort } from '../utils' | 13 | import { getSort } from '../utils' |
13 | import { VideoChannelModel } from '../video/video-channel' | 14 | import { VideoChannelModel } from '../video/video-channel' |
15 | import { VideoCommentModel } from '../video/video-comment' | ||
14 | import { UserModel } from './user' | 16 | import { 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 |