]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/activitypub/actor-follow.ts
Merge branch 'release/v1.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / models / activitypub / actor-follow.ts
index 81fcf700187fd86160116d0dc30548849b10a027..3373355efff67f0aa8f852d78a8ab00249e82ed3 100644 (file)
@@ -19,7 +19,7 @@ import {
   UpdatedAt
 } from 'sequelize-typescript'
 import { FollowState } from '../../../shared/models/actors'
-import { AccountFollow } from '../../../shared/models/actors/follow.model'
+import { ActorFollow } from '../../../shared/models/actors/follow.model'
 import { logger } from '../../helpers/logger'
 import { getServerActor } from '../../helpers/utils'
 import { ACTOR_FOLLOW_SCORE } from '../../initializers'
@@ -169,9 +169,6 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
 
   static loadByActorAndTargetNameAndHostForAPI (actorId: number, targetName: string, targetHost: string, t?: Sequelize.Transaction) {
     const actorFollowingPartInclude: IIncludeOptions = {
-      attributes: {
-        exclude: unusedActorAttributesForAPI
-      },
       model: ActorModel,
       required: true,
       as: 'ActorFollowing',
@@ -203,7 +200,12 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
         actorId
       },
       include: [
-        actorFollowingPartInclude
+        actorFollowingPartInclude,
+        {
+          model: ActorModel,
+          required: true,
+          as: 'ActorFollower'
+        }
       ],
       transaction: t
     }
@@ -278,7 +280,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
     return ActorFollowModel.findAll(query)
   }
 
-  static listFollowingForApi (id: number, start: number, count: number, sort: string) {
+  static listFollowingForApi (id: number, start: number, count: number, sort: string, search?: string) {
     const query = {
       distinct: true,
       offset: start,
@@ -297,7 +299,17 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
           model: ActorModel,
           as: 'ActorFollowing',
           required: true,
-          include: [ ServerModel ]
+          include: [
+            {
+              model: ServerModel,
+              required: true,
+              where: search ? {
+                host: {
+                  [Sequelize.Op.iLike]: '%' + search + '%'
+                }
+              } : undefined
+            }
+          ]
         }
       ]
     }
@@ -311,6 +323,49 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
       })
   }
 
+  static listFollowersForApi (id: number, start: number, count: number, sort: string, search?: string) {
+    const query = {
+      distinct: true,
+      offset: start,
+      limit: count,
+      order: getSort(sort),
+      include: [
+        {
+          model: ActorModel,
+          required: true,
+          as: 'ActorFollower',
+          include: [
+            {
+              model: ServerModel,
+              required: true,
+              where: search ? {
+                host: {
+                  [ Sequelize.Op.iLike ]: '%' + search + '%'
+                }
+              } : undefined
+            }
+          ]
+        },
+        {
+          model: ActorModel,
+          as: 'ActorFollowing',
+          required: true,
+          where: {
+            id
+          }
+        }
+      ]
+    }
+
+    return ActorFollowModel.findAndCountAll(query)
+                           .then(({ rows, count }) => {
+                             return {
+                               data: rows,
+                               total: count
+                             }
+                           })
+  }
+
   static listSubscriptionsForApi (id: number, start: number, count: number, sort: string) {
     const query = {
       attributes: [],
@@ -323,15 +378,13 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
       },
       include: [
         {
-          attributes: {
-            exclude: unusedActorAttributesForAPI
-          },
-          model: ActorModel,
+          attributes: [ 'id' ],
+          model: ActorModel.unscoped(),
           as: 'ActorFollowing',
           required: true,
           include: [
             {
-              model: VideoChannelModel,
+              model: VideoChannelModel.unscoped(),
               required: true,
               include: [
                 {
@@ -342,7 +395,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
                   required: true
                 },
                 {
-                  model: AccountModel,
+                  model: AccountModel.unscoped(),
                   required: true,
                   include: [
                     {
@@ -370,39 +423,6 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
                            })
   }
 
-  static listFollowersForApi (id: number, start: number, count: number, sort: string) {
-    const query = {
-      distinct: true,
-      offset: start,
-      limit: count,
-      order: getSort(sort),
-      include: [
-        {
-          model: ActorModel,
-          required: true,
-          as: 'ActorFollower',
-          include: [ ServerModel ]
-        },
-        {
-          model: ActorModel,
-          as: 'ActorFollowing',
-          required: true,
-          where: {
-            id
-          }
-        }
-      ]
-    }
-
-    return ActorFollowModel.findAndCountAll(query)
-      .then(({ rows, count }) => {
-        return {
-          data: rows,
-          total: count
-        }
-      })
-  }
-
   static listAcceptedFollowerUrlsForApi (actorIds: number[], t: Sequelize.Transaction, start?: number, count?: number) {
     return ActorFollowModel.createListAcceptedFollowForApiQuery('followers', actorIds, t, start, count)
   }
@@ -529,7 +549,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
     return ActorFollowModel.findAll(query)
   }
 
-  toFormattedJSON (): AccountFollow {
+  toFormattedJSON (): ActorFollow {
     const follower = this.ActorFollower.toFormattedJSON()
     const following = this.ActorFollowing.toFormattedJSON()