]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/activitypub/actor-follow.ts
Handle views for live videos
[github/Chocobozzz/PeerTube.git] / server / models / activitypub / actor-follow.ts
index 3e85cc329e9569b2a0226602056782c7d4d11778..10c13304f8dd15da57d2911fa724e88cacb67828 100644 (file)
@@ -22,7 +22,7 @@ import { ActorFollow } from '../../../shared/models/actors/follow.model'
 import { logger } from '../../helpers/logger'
 import { ACTOR_FOLLOW_SCORE, FOLLOW_STATES, SERVER_ACTOR_NAME } from '../../initializers/constants'
 import { ServerModel } from '../server/server'
-import { createSafeIn, getFollowsSort, getSort } from '../utils'
+import { createSafeIn, getFollowsSort, getSort, searchAttribute } from '../utils'
 import { ActorModel, unusedActorAttributesForAPI } from './actor'
 import { VideoChannelModel } from '../video/video-channel'
 import { AccountModel } from '../account/account'
@@ -440,16 +440,34 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
                            })
   }
 
-  static listSubscriptionsForApi (actorId: number, start: number, count: number, sort: string) {
+  static listSubscriptionsForApi (options: {
+    actorId: number
+    start: number
+    count: number
+    sort: string
+    search?: string
+  }) {
+    const { actorId, start, count, sort } = options
+    const where = {
+      actorId: actorId
+    }
+
+    if (options.search) {
+      Object.assign(where, {
+        [Op.or]: [
+          searchAttribute(options.search, '$ActorFollowing.preferredUsername$'),
+          searchAttribute(options.search, '$ActorFollowing.VideoChannel.name$')
+        ]
+      })
+    }
+
     const query = {
       attributes: [],
       distinct: true,
       offset: start,
       limit: count,
       order: getSort(sort),
-      where: {
-        actorId: actorId
-      },
+      where,
       include: [
         {
           attributes: [ 'id' ],