X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Faccount%2Faccount.ts;h=71a9b8ccbcf1df75f52bbe185de04b6fc8916f8b;hb=3c10840fa90fc88fc98e8169faf4745ff6c80893;hp=665ecd595cf604a2b8c13e1b036028a4110f5fd2;hpb=eb34ec30e0b57286fc6f85160490d2e973a3b0b1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 665ecd595..71a9b8ccb 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -52,6 +52,7 @@ export enum ScopeNames { export type SummaryOptions = { actorRequired?: boolean // Default: true whereActor?: WhereOptions + whereServer?: WhereOptions withAccountBlockerIds?: number[] } @@ -65,12 +66,11 @@ export type SummaryOptions = { })) @Scopes(() => ({ [ScopeNames.SUMMARY]: (options: SummaryOptions = {}) => { - const whereActor = options.whereActor || undefined - const serverInclude: IncludeOptions = { attributes: [ 'host' ], model: ServerModel.unscoped(), - required: false + required: !!options.whereServer, + where: options.whereServer } const queryInclude: Includeable[] = [ @@ -78,7 +78,7 @@ export type SummaryOptions = { attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ], model: ActorModel.unscoped(), required: options.actorRequired ?? true, - where: whereActor, + where: options.whereActor, include: [ serverInclude, @@ -99,7 +99,7 @@ export type SummaryOptions = { queryInclude.push({ attributes: [ 'id' ], model: AccountBlocklistModel.unscoped(), - as: 'BlockedAccounts', + as: 'BlockedBy', required: false, where: { accountId: { @@ -228,10 +228,10 @@ export class AccountModel extends Model>> { name: 'targetAccountId', allowNull: false }, - as: 'BlockedAccounts', + as: 'BlockedBy', onDelete: 'CASCADE' }) - BlockedAccounts: AccountBlocklistModel[] + BlockedBy: AccountBlocklistModel[] @BeforeDestroy static async sendDeleteIfOwned (instance: AccountModel, options) { @@ -457,6 +457,6 @@ export class AccountModel extends Model>> { } isBlocked () { - return this.BlockedAccounts && this.BlockedAccounts.length !== 0 + return this.BlockedBy && this.BlockedBy.length !== 0 } }