X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-channel.ts;h=6241a75a30bfffd499cede0102bd4734781cc838;hb=970ceac0a6bf4990b8924738591df4949491ec9b;hp=d73be18d66761bb874518872790965d678fe70d1;hpb=91b6631984fa7097bd60aa013d1cf041d7b95f58;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index d73be18d6..6241a75a3 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -24,7 +24,7 @@ import { isVideoChannelSupportValid } from '../../helpers/custom-validators/video-channels' import { sendDeleteActor } from '../../lib/activitypub/send' -import { AccountModel, ScopeNames as AccountModelScopeNames } from '../account/account' +import { AccountModel, ScopeNames as AccountModelScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account' import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor' import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' @@ -58,6 +58,11 @@ type AvailableForListOptions = { actorId: number } +export type SummaryOptions = { + withAccount?: boolean // Default: false + withAccountBlockerIds?: number[] +} + @DefaultScope(() => ({ include: [ { @@ -67,12 +72,12 @@ type AvailableForListOptions = { ] })) @Scopes(() => ({ - [ScopeNames.SUMMARY]: (withAccount = false) => { + [ScopeNames.SUMMARY]: (options: SummaryOptions = {}) => { const base: FindOptions = { attributes: [ 'name', 'description', 'id', 'actorId' ], include: [ { - attributes: [ 'uuid', 'preferredUsername', 'url', 'serverId', 'avatarId' ], + attributes: [ 'preferredUsername', 'url', 'serverId', 'avatarId' ], model: ActorModel.unscoped(), required: true, include: [ @@ -90,9 +95,11 @@ type AvailableForListOptions = { ] } - if (withAccount === true) { + if (options.withAccount === true) { base.include.push({ - model: AccountModel.scope(AccountModelScopeNames.SUMMARY), + model: AccountModel.scope({ + method: [ AccountModelScopeNames.SUMMARY, { withAccountBlockerIds: options.withAccountBlockerIds } as AccountSummaryOptions ] + }), required: true }) } @@ -387,24 +394,6 @@ export class VideoChannelModel extends Model { .findByPk(id) } - static loadByUUIDAndPopulateAccount (uuid: string) { - const query = { - include: [ - { - model: ActorModel, - required: true, - where: { - uuid - } - } - ] - } - - return VideoChannelModel - .scope([ ScopeNames.WITH_ACCOUNT ]) - .findOne(query) - } - static loadByUrlAndPopulateAccount (url: string) { const query = { include: [ @@ -510,7 +499,6 @@ export class VideoChannelModel extends Model { return { id: this.id, - uuid: actor.uuid, name: actor.name, displayName: this.getDisplayName(), url: actor.url,