Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Delete remote actor too

Chocobozzz5ae90e0757b2
diff --git a/server/core/models/account/account.ts b/server/core/models/account/account.ts
index f86a290623..9144a98237 100644
--- a/server/core/models/account/account.ts
+++ b/server/core/models/account/account.ts
@@ -2,6 +2,7 @@ import { Account, AccountSummary } from '@peertube/peertube-models'
import { ModelCache } from '@server/models/shared/model-cache.js'
import { FindOptions, IncludeOptions, Includeable, Op, Transaction, WhereOptions } from 'sequelize'
import {
+ AfterDestroy,
AllowNull,
BeforeDestroy,
BelongsTo, Column,
@@ -270,6 +271,18 @@ export class AccountModel extends SequelizeModel<AccountModel> {
return undefined
}
+ @AfterDestroy
+ static async deleteActorIfRemote (instance: AccountModel, options) {
+ if (!instance.Actor) {
+ instance.Actor = await instance.$get('Actor', { transaction: options.transaction })
+ }
+
+ // Remote actor, delete it
+ if (instance.Actor.serverId) {
+ await instance.Actor.destroy({ transaction: options.transaction })
+ }
+ }
+
// ---------------------------------------------------------------------------
static getSQLAttributes (tableName: string, aliasPrefix = '') {
diff --git a/server/core/models/video/video-channel.ts b/server/core/models/video/video-channel.ts
index 3b8795d07d..bb920c68b5 100644
--- a/server/core/models/video/video-channel.ts
+++ b/server/core/models/video/video-channel.ts
@@ -33,10 +33,11 @@ import { sendDeleteActor } from '../../lib/activitypub/send/index.js'
import {
MChannelAP,
MChannelBannerAccountDefault,
+ MChannelDefault,
MChannelFormattable,
MChannelHost,
MChannelSummaryFormattable,
- type MChannel, MChannelDefault
+ type MChannel
} from '../../types/models/video/index.js'
import { AccountModel, ScopeNames as AccountModelScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account.js'
import { ActorFollowModel } from '../actor/actor-follow.js'
@@ -44,11 +45,11 @@ import { ActorImageModel } from '../actor/actor-image.js'
import { ActorModel, unusedActorAttributesForAPI } from '../actor/actor.js'
import { ServerModel } from '../server/server.js'
import {
- SequelizeModel,
buildServerIdsFollowedBy,
buildTrigramSearchIndex,
createSimilarityAttribute,
getSort,
+ SequelizeModel,
setAsUpdated,
throwIfNotValid
} from '../shared/index.js'
@@ -447,6 +448,18 @@ export class VideoChannelModel extends SequelizeModel<VideoChannelModel> {
return undefined
}
+ @AfterDestroy
+ static async deleteActorIfRemote (instance: VideoChannelModel, options) {
+ if (!instance.Actor) {
+ instance.Actor = await instance.$get('Actor', { transaction: options.transaction })
+ }
+
+ // Remote actor, delete it
+ if (instance.Actor.serverId) {
+ await instance.Actor.destroy({ transaction: options.transaction })
+ }
+ }
+
static countByAccount (accountId: number) {
const query = {
where: {