Delete remote actor too

This commit is contained in:
Chocobozzz 2024-09-17 08:31:32 +02:00
parent d794988ebd
commit 5ae90e0757
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 28 additions and 2 deletions

View File

@ -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 = '') {

View File

@ -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: {