]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-playlist.ts
Fix embed on mastodon
[github/Chocobozzz/PeerTube.git] / server / models / video / video-playlist.ts
index 278d80ac051d2144cd34be068256b3425f3d2e93..bcdda36e5cd589f0943a798cd3272dbff17c2d89 100644 (file)
@@ -45,7 +45,8 @@ import { ActivityIconObject } from '../../../shared/models/activitypub/objects'
 import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize'
 import * as Bluebird from 'bluebird'
 import {
-  MVideoPlaylistAccountThumbnail, MVideoPlaylistAP,
+  MVideoPlaylistAccountThumbnail,
+  MVideoPlaylistAP,
   MVideoPlaylistFormattable,
   MVideoPlaylistFull,
   MVideoPlaylistFullSummary,
@@ -67,7 +68,8 @@ type AvailableForListOptions = {
   type?: VideoPlaylistType
   accountId?: number
   videoChannelId?: number
-  privateAndUnlisted?: boolean
+  listMyPlaylists?: boolean,
+  search?: string
 }
 
 @Scopes(() => ({
@@ -122,27 +124,31 @@ type AvailableForListOptions = {
     ]
   },
   [ ScopeNames.AVAILABLE_FOR_LIST ]: (options: AvailableForListOptions) => {
-    // Only list local playlists OR playlists that are on an instance followed by actorId
-    const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId)
-    const whereActor = {
-      [ Op.or ]: [
-        {
-          serverId: null
-        },
-        {
-          serverId: {
-            [ Op.in ]: literal(inQueryInstanceFollow)
-          }
-        }
-      ]
-    }
+
+    let whereActor: WhereOptions = {}
 
     const whereAnd: WhereOptions[] = []
 
-    if (options.privateAndUnlisted !== true) {
+    if (options.listMyPlaylists !== true) {
       whereAnd.push({
         privacy: VideoPlaylistPrivacy.PUBLIC
       })
+
+      // Only list local playlists OR playlists that are on an instance followed by actorId
+      const inQueryInstanceFollow = buildServerIdsFollowedBy(options.followerActorId)
+
+      whereActor = {
+        [ Op.or ]: [
+          {
+            serverId: null
+          },
+          {
+            serverId: {
+              [ Op.in ]: literal(inQueryInstanceFollow)
+            }
+          }
+        ]
+      }
     }
 
     if (options.accountId) {
@@ -163,6 +169,14 @@ type AvailableForListOptions = {
       })
     }
 
+    if (options.search) {
+      whereAnd.push({
+        name: {
+          [ Op.iLike ]: '%' + options.search + '%'
+        }
+      })
+    }
+
     const where = {
       [Op.and]: whereAnd
     }
@@ -291,7 +305,8 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
     type?: VideoPlaylistType,
     accountId?: number,
     videoChannelId?: number,
-    privateAndUnlisted?: boolean
+    listMyPlaylists?: boolean,
+    search?: string
   }) {
     const query = {
       offset: options.start,
@@ -308,7 +323,8 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
             followerActorId: options.followerActorId,
             accountId: options.accountId,
             videoChannelId: options.videoChannelId,
-            privateAndUnlisted: options.privateAndUnlisted
+            listMyPlaylists: options.listMyPlaylists,
+            search: options.search
           } as AvailableForListOptions
         ]
       },