aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-18 10:53:54 +0100
committerChocobozzz <me@florianbigard.com>2018-01-18 15:42:20 +0100
commitf05a1c30c15d2ae35c11e241ca039a72eeb7d6ad (patch)
tree6d90c0de5dd3ad506e738d447e4f396951ed5624 /server/models/account
parent1174a8479ab9ee47b3305d668fe757435057a298 (diff)
downloadPeerTube-f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad.tar.gz
PeerTube-f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad.tar.zst
PeerTube-f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad.zip
Don't show videos of remote instance after unfollow
Diffstat (limited to 'server/models/account')
-rw-r--r--server/models/account/account.ts26
-rw-r--r--server/models/account/user.ts3
2 files changed, 23 insertions, 6 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
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<UserModel> {
94 94
95 @HasOne(() => AccountModel, { 95 @HasOne(() => AccountModel, {
96 foreignKey: 'userId', 96 foreignKey: 'userId',
97 onDelete: 'cascade' 97 onDelete: 'cascade',
98 hooks: true
98 }) 99 })
99 Account: AccountModel 100 Account: AccountModel
100 101