]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-comment.ts
Federate entire description
[github/Chocobozzz/PeerTube.git] / server / models / video / video-comment.ts
index 2d60c6a30218527ce70b26e8c0b31ee76af2a892..af9614d30439eb5dcd63a9d86b337bdfa62def77 100644 (file)
@@ -1,4 +1,3 @@
-import { uniq } from 'lodash'
 import { FindOptions, Op, Order, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize'
 import {
   AllowNull,
@@ -14,8 +13,10 @@ import {
   Table,
   UpdatedAt
 } from 'sequelize-typescript'
+import { exists } from '@server/helpers/custom-validators/misc'
 import { getServerActor } from '@server/models/application/application'
 import { MAccount, MAccountId, MUserAccountId } from '@server/types/models'
+import { uniqify } from '@shared/core-utils'
 import { VideoPrivacy } from '@shared/models'
 import { AttributesOnly } from '@shared/typescript-utils'
 import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects'
@@ -312,12 +313,13 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
     count: number
     sort: string
 
+    onLocalVideo?: boolean
     isLocal?: boolean
     search?: string
     searchAccount?: string
     searchVideo?: string
   }) {
-    const { start, count, sort, isLocal, search, searchAccount, searchVideo } = parameters
+    const { start, count, sort, isLocal, search, searchAccount, searchVideo, onLocalVideo } = parameters
 
     const where: WhereOptions = {
       deletedAt: null
@@ -363,6 +365,10 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
       Object.assign(whereVideo, searchAttribute(searchVideo, 'name'))
     }
 
+    if (exists(onLocalVideo)) {
+      Object.assign(whereVideo, { remote: !onLocalVideo })
+    }
+
     const getQuery = (forCount: boolean) => {
       return {
         offset: start,
@@ -683,11 +689,11 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
     const totalLocalVideoComments = await VideoCommentModel.count({
       include: [
         {
-          model: AccountModel,
+          model: AccountModel.unscoped(),
           required: true,
           include: [
             {
-              model: ActorModel,
+              model: ActorModel.unscoped(),
               required: true,
               where: {
                 serverId: null
@@ -796,7 +802,7 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
       )
     }
 
-    return uniq(result)
+    return uniqify(result)
   }
 
   toFormattedJSON (this: MCommentFormattable) {
@@ -913,7 +919,7 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
 
     if (isVideoOwned) {
       const videoOwnerAccount = await AccountModel.loadAccountIdFromVideo(videoId)
-      blockerAccountIds.push(videoOwnerAccount.id)
+      if (videoOwnerAccount) blockerAccountIds.push(videoOwnerAccount.id)
     }
 
     return blockerAccountIds