]> 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 ef87a7ee9586f757d7dc6ca9a67d9c1d8c7a3550..bcdda36e5cd589f0943a798cd3272dbff17c2d89 100644 (file)
@@ -13,11 +13,10 @@ import {
   Model,
   Scopes,
   Table,
-  UpdatedAt,
-  Sequelize
+  UpdatedAt
 } from 'sequelize-typescript'
 import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
-import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid, createSimilarityAttribute } from '../utils'
+import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils'
 import {
   isVideoPlaylistDescriptionValid,
   isVideoPlaylistNameValid,
@@ -46,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,
@@ -68,7 +68,7 @@ type AvailableForListOptions = {
   type?: VideoPlaylistType
   accountId?: number
   videoChannelId?: number
-  privateAndUnlisted?: boolean,
+  listMyPlaylists?: boolean,
   search?: string
 }
 
@@ -124,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) {
@@ -166,18 +170,9 @@ type AvailableForListOptions = {
     }
 
     if (options.search) {
-      const escapedSearch = VideoPlaylistModel.sequelize.escape(options.search)
-      const escapedLikeSearch = VideoPlaylistModel.sequelize.escape('%' + options.search + '%')
       whereAnd.push({
-        id: {
-          [ Op.in ]: Sequelize.literal(
-            '(' +
-            'SELECT "videoPlaylist"."id" FROM "videoPlaylist" ' +
-            'WHERE ' +
-            'lower(immutable_unaccent("videoPlaylist"."name")) % lower(immutable_unaccent(' + escapedSearch + ')) OR ' +
-            'lower(immutable_unaccent("videoPlaylist"."name")) LIKE lower(immutable_unaccent(' + escapedLikeSearch + '))' +
-            ')'
-          )
+        name: {
+          [ Op.iLike ]: '%' + options.search + '%'
         }
       })
     }
@@ -310,7 +305,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
     type?: VideoPlaylistType,
     accountId?: number,
     videoChannelId?: number,
-    privateAndUnlisted?: boolean,
+    listMyPlaylists?: boolean,
     search?: string
   }) {
     const query = {
@@ -328,7 +323,7 @@ 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
         ]