From f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Jan 2018 10:53:54 +0100 Subject: Don't show videos of remote instance after unfollow --- server/models/account/account.ts | 26 +++++++++++++++++++++----- server/models/account/user.ts | 3 ++- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'server/models/account') 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 @@ import * as Sequelize from 'sequelize' import { - AfterDestroy, AllowNull, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Model, Table, + AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Model, Table, UpdatedAt } from 'sequelize-typescript' import { Account } from '../../../shared/models/actors' +import { logger } from '../../helpers/logger' import { sendDeleteActor } from '../../lib/activitypub/send' import { ActorModel } from '../activitypub/actor' import { ApplicationModel } from '../application/application' @@ -11,6 +12,7 @@ import { AvatarModel } from '../avatar/avatar' import { ServerModel } from '../server/server' import { getSort } from '../utils' import { VideoChannelModel } from '../video/video-channel' +import { VideoCommentModel } from '../video/video-comment' import { UserModel } from './user' @DefaultScope({ @@ -80,7 +82,7 @@ export class AccountModel extends Model { }, onDelete: 'cascade' }) - Account: ApplicationModel + Application: ApplicationModel @HasMany(() => VideoChannelModel, { foreignKey: { @@ -91,10 +93,24 @@ export class AccountModel extends Model { }) VideoChannels: VideoChannelModel[] - @AfterDestroy - static sendDeleteIfOwned (instance: AccountModel) { + @HasMany(() => VideoCommentModel, { + foreignKey: { + allowNull: false + }, + onDelete: 'cascade', + hooks: true + }) + VideoComments: VideoCommentModel[] + + @BeforeDestroy + static async sendDeleteIfOwned (instance: AccountModel, options) { + if (!instance.Actor) { + instance.Actor = await instance.$get('Actor', { transaction: options.transaction }) as ActorModel + } + if (instance.isOwned()) { - return sendDeleteActor(instance.Actor, undefined) + logger.debug('Sending delete of actor of account %s.', instance.Actor.url) + return sendDeleteActor(instance.Actor, options.transaction) } return undefined diff --git a/server/models/account/user.ts b/server/models/account/user.ts index e37fd4d3b..8eb88062a 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -94,7 +94,8 @@ export class UserModel extends Model { @HasOne(() => AccountModel, { foreignKey: 'userId', - onDelete: 'cascade' + onDelete: 'cascade', + hooks: true }) Account: AccountModel -- cgit v1.2.3