]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-query-builder.ts
Do not display deleted comments in RSS feed
[github/Chocobozzz/PeerTube.git] / server / models / video / video-query-builder.ts
index 015bf43de1ebce7bcbf2fd1de51a45f0a965c0b5..455f9f30ff032c158404535196db985de1e0e36d 100644 (file)
@@ -207,15 +207,14 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
     const languagesQueryParts: string[] = []
 
     if (languages.length !== 0) {
-      languagesQueryParts.push('("video"."language" IN (:languageOneOf)')
+      languagesQueryParts.push('"video"."language" IN (:languageOneOf)')
       replacements.languageOneOf = languages
 
       languagesQueryParts.push(
-        '  EXISTS (' +
-        '    SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' +
-        '    IN (' + createSafeIn(model, languages) + ') AND ' +
-        '    "videoCaption"."videoId" = "video"."id"' +
-        '  )' +
+        'EXISTS (' +
+        '  SELECT 1 FROM "videoCaption" WHERE "videoCaption"."language" ' +
+        '  IN (' + createSafeIn(model, languages) + ') AND ' +
+        '  "videoCaption"."videoId" = "video"."id"' +
         ')'
       )
     }
@@ -224,7 +223,9 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
       languagesQueryParts.push('"video"."language" IS NULL')
     }
 
-    and.push(languagesQueryParts.join(' OR '))
+    if (languagesQueryParts.length !== 0) {
+      and.push('(' + languagesQueryParts.join(' OR ') + ')')
+    }
   }
 
   // We don't exclude results in this if so if we do a count we don't need to add this complex clauses
@@ -320,6 +321,10 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
   if (options.isCount !== true) {
 
     if (exists(options.sort)) {
+      if (options.sort === '-originallyPublishedAt' || options.sort === 'originallyPublishedAt') {
+        attributes.push('COALESCE("video"."originallyPublishedAt", "video"."publishedAt") AS "publishedAtForOrder"')
+      }
+
       order = buildOrder(model, options.sort)
       suffix += `${order} `
     }
@@ -364,6 +369,8 @@ function buildOrder (model: typeof Model, value: string) {
 
   if (field.toLowerCase() === 'match') { // Search
     firstSort = '"similarity"'
+  } else if (field === 'originallyPublishedAt') {
+    firstSort = '"publishedAtForOrder"'
   } else if (field.includes('.')) {
     firstSort = field
   } else {