]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-channel.ts
Fix multiple server tests
[github/Chocobozzz/PeerTube.git] / server / models / video / video-channel.ts
index d73be18d66761bb874518872790965d678fe70d1..6241a75a30bfffd499cede0102bd4734781cc838 100644 (file)
@@ -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<VideoChannelModel> {
       .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<VideoChannelModel> {
 
     return {
       id: this.id,
-      uuid: actor.uuid,
       name: actor.name,
       displayName: this.getDisplayName(),
       url: actor.url,