]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-channel.ts
Merge branch 'release/1.4.0' into develop
[github/Chocobozzz/PeerTube.git] / server / models / video / video-channel.ts
index 79b9e7d2ba1e83190e4e3a975ff98dd873e01536..7178631b47119ee3efc251255b11fcda5bdaa4bc 100644 (file)
@@ -37,8 +37,10 @@ import * as Bluebird from 'bluebird'
 import {
   MChannelAccountDefault,
   MChannelActor,
-  MChannelActorAccountDefault,
-  MChannelActorAccountDefaultVideos
+  MChannelActorAccountDefaultVideos,
+  MChannelAP,
+  MChannelFormattable,
+  MChannelSummaryFormattable
 } from '../../typings/models/video'
 
 // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
@@ -376,13 +378,13 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
       })
   }
 
-  static loadByIdAndPopulateAccount (id: number): Bluebird<MChannelActorAccountDefault> {
+  static loadByIdAndPopulateAccount (id: number): Bluebird<MChannelAccountDefault> {
     return VideoChannelModel.unscoped()
       .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
       .findByPk(id)
   }
 
-  static loadByIdAndAccount (id: number, accountId: number): Bluebird<MChannelActorAccountDefault> {
+  static loadByIdAndAccount (id: number, accountId: number): Bluebird<MChannelAccountDefault> {
     const query = {
       where: {
         id,
@@ -395,7 +397,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
       .findOne(query)
   }
 
-  static loadAndPopulateAccount (id: number): Bluebird<MChannelActorAccountDefault> {
+  static loadAndPopulateAccount (id: number): Bluebird<MChannelAccountDefault> {
     return VideoChannelModel.unscoped()
       .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
       .findByPk(id)
@@ -427,7 +429,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
     return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host)
   }
 
-  static loadLocalByNameAndPopulateAccount (name: string): Bluebird<MChannelActorAccountDefault> {
+  static loadLocalByNameAndPopulateAccount (name: string): Bluebird<MChannelAccountDefault> {
     const query = {
       include: [
         {
@@ -446,7 +448,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
       .findOne(query)
   }
 
-  static loadByNameAndHostAndPopulateAccount (name: string, host: string): Bluebird<MChannelActorAccountDefault> {
+  static loadByNameAndHostAndPopulateAccount (name: string, host: string): Bluebird<MChannelAccountDefault> {
     const query = {
       include: [
         {
@@ -483,7 +485,20 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
       .findByPk(id, options)
   }
 
-  toFormattedJSON (): VideoChannel {
+  toFormattedSummaryJSON (this: MChannelSummaryFormattable): VideoChannelSummary {
+    const actor = this.Actor.toFormattedSummaryJSON()
+
+    return {
+      id: this.id,
+      name: actor.name,
+      displayName: this.getDisplayName(),
+      url: actor.url,
+      host: actor.host,
+      avatar: actor.avatar
+    }
+  }
+
+  toFormattedJSON (this: MChannelFormattable): VideoChannel {
     const actor = this.Actor.toFormattedJSON()
     const videoChannel = {
       id: this.id,
@@ -501,20 +516,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
     return Object.assign(actor, videoChannel)
   }
 
-  toFormattedSummaryJSON (): VideoChannelSummary {
-    const actor = this.Actor.toFormattedJSON()
-
-    return {
-      id: this.id,
-      name: actor.name,
-      displayName: this.getDisplayName(),
-      url: actor.url,
-      host: actor.host,
-      avatar: actor.avatar
-    }
-  }
-
-  toActivityPubObject (): ActivityPubActor {
+  toActivityPubObject (this: MChannelAP): ActivityPubActor {
     const obj = this.Actor.toActivityPubObject(this.name, 'VideoChannel')
 
     return Object.assign(obj, {