aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-comment.ts67
1 files changed, 53 insertions, 14 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 6d60271e6..7c890ce6d 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -1,19 +1,17 @@
1import * as Bluebird from 'bluebird'
2import { uniq } from 'lodash'
3import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize'
1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' 4import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
5import { getServerActor } from '@server/models/application/application'
6import { MAccount, MAccountId, MUserAccountId } from '@server/typings/models'
7import { VideoPrivacy } from '@shared/models'
2import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects' 8import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects'
3import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' 9import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object'
4import { VideoComment } from '../../../shared/models/videos/video-comment.model' 10import { VideoComment } from '../../../shared/models/videos/video-comment.model'
5import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
6import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
7import { AccountModel } from '../account/account'
8import { ActorModel } from '../activitypub/actor'
9import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils'
10import { VideoModel } from './video'
11import { VideoChannelModel } from './video-channel'
12import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' 11import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor'
12import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
13import { regexpCapture } from '../../helpers/regexp' 13import { regexpCapture } from '../../helpers/regexp'
14import { uniq } from 'lodash' 14import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
15import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize'
16import * as Bluebird from 'bluebird'
17import { 15import {
18 MComment, 16 MComment,
19 MCommentAP, 17 MCommentAP,
@@ -25,9 +23,11 @@ import {
25 MCommentOwnerVideoFeed, 23 MCommentOwnerVideoFeed,
26 MCommentOwnerVideoReply 24 MCommentOwnerVideoReply
27} from '../../typings/models/video' 25} from '../../typings/models/video'
28import { MUserAccountId } from '@server/typings/models' 26import { AccountModel } from '../account/account'
29import { VideoPrivacy } from '@shared/models' 27import { ActorModel } from '../activitypub/actor'
30import { getServerActor } from '@server/models/application/application' 28import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils'
29import { VideoModel } from './video'
30import { VideoChannelModel } from './video-channel'
31 31
32enum ScopeNames { 32enum ScopeNames {
33 WITH_ACCOUNT = 'WITH_ACCOUNT', 33 WITH_ACCOUNT = 'WITH_ACCOUNT',
@@ -415,6 +415,43 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
415 .findAll(query) 415 .findAll(query)
416 } 416 }
417 417
418 static listForBulkDelete (ofAccount: MAccount, filter: { onVideosOfAccount?: MAccountId } = {}) {
419 const accountWhere = filter.onVideosOfAccount
420 ? { id: filter.onVideosOfAccount.id }
421 : {}
422
423 const query = {
424 limit: 1000,
425 where: {
426 deletedAt: null,
427 accountId: ofAccount.id
428 },
429 include: [
430 {
431 model: VideoModel,
432 required: true,
433 include: [
434 {
435 model: VideoChannelModel,
436 required: true,
437 include: [
438 {
439 model: AccountModel,
440 required: true,
441 where: accountWhere
442 }
443 ]
444 }
445 ]
446 }
447 ]
448 }
449
450 return VideoCommentModel
451 .scope([ ScopeNames.WITH_ACCOUNT ])
452 .findAll(query)
453 }
454
418 static async getStats () { 455 static async getStats () {
419 const totalLocalVideoComments = await VideoCommentModel.count({ 456 const totalLocalVideoComments = await VideoCommentModel.count({
420 include: [ 457 include: [
@@ -450,7 +487,9 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
450 videoId, 487 videoId,
451 accountId: { 488 accountId: {
452 [Op.notIn]: buildLocalAccountIdsIn() 489 [Op.notIn]: buildLocalAccountIdsIn()
453 } 490 },
491 // Do not delete Tombstones
492 deletedAt: null
454 } 493 }
455 } 494 }
456 495