]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-comment.ts
Add banners support
[github/Chocobozzz/PeerTube.git] / server / models / video / video-comment.ts
index cfd1d5b7a6188be05cbefc02317e53ccfe8e200f..151c2bc81a793fd11ec3622ec1cc363fe7fcbf3a 100644 (file)
@@ -1,5 +1,5 @@
 import { uniq } from 'lodash'
-import { FindAndCountOptions, FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize'
+import { FindAndCountOptions, FindOptions, Op, Order, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize'
 import {
   AllowNull,
   BelongsTo,
@@ -483,20 +483,26 @@ export class VideoCommentModel extends Model {
       order: [ [ 'createdAt', 'ASC' ], [ 'updatedAt', 'ASC' ] ] as Order,
       where: {
         videoId,
-        [Op.or]: [
-          { id: threadId },
-          { originCommentId: threadId }
-        ],
-        [Op.or]: [
+        [Op.and]: [
           {
-            accountId: {
-              [Op.notIn]: Sequelize.literal(
-                '(' + buildBlockedAccountSQL(blockerAccountIds) + ')'
-              )
-            }
+            [Op.or]: [
+              { id: threadId },
+              { originCommentId: threadId }
+            ]
           },
           {
-            accountId: null
+            [Op.or]: [
+              {
+                accountId: {
+                  [Op.notIn]: Sequelize.literal(
+                    '(' + buildBlockedAccountSQL(blockerAccountIds) + ')'
+                  )
+                }
+              },
+              {
+                accountId: null
+              }
+            ]
           }
         ]
       }
@@ -690,6 +696,18 @@ export class VideoCommentModel extends Model {
     }
   }
 
+  static listRemoteCommentUrlsOfLocalVideos () {
+    const query = `SELECT "videoComment".url FROM "videoComment" ` +
+      `INNER JOIN account ON account.id = "videoComment"."accountId" ` +
+      `INNER JOIN actor ON actor.id = "account"."actorId" AND actor."serverId" IS NOT NULL ` +
+      `INNER JOIN video ON video.id = "videoComment"."videoId" AND video.remote IS FALSE`
+
+    return VideoCommentModel.sequelize.query<{ url: string }>(query, {
+      type: QueryTypes.SELECT,
+      raw: true
+    }).then(rows => rows.map(r => r.url))
+  }
+
   static cleanOldCommentsOf (videoId: number, beforeUpdatedAt: Date) {
     const query = {
       where: {