diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video-comment.ts | 67 |
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 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { uniq } from 'lodash' | ||
3 | import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' | ||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 4 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
5 | import { getServerActor } from '@server/models/application/application' | ||
6 | import { MAccount, MAccountId, MUserAccountId } from '@server/typings/models' | ||
7 | import { VideoPrivacy } from '@shared/models' | ||
2 | import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects' | 8 | import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects' |
3 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' | 9 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' |
4 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' | 10 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' |
5 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
6 | import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' | ||
7 | import { AccountModel } from '../account/account' | ||
8 | import { ActorModel } from '../activitypub/actor' | ||
9 | import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils' | ||
10 | import { VideoModel } from './video' | ||
11 | import { VideoChannelModel } from './video-channel' | ||
12 | import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' | 11 | import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' |
12 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
13 | import { regexpCapture } from '../../helpers/regexp' | 13 | import { regexpCapture } from '../../helpers/regexp' |
14 | import { uniq } from 'lodash' | 14 | import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' |
15 | import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' | ||
16 | import * as Bluebird from 'bluebird' | ||
17 | import { | 15 | import { |
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' |
28 | import { MUserAccountId } from '@server/typings/models' | 26 | import { AccountModel } from '../account/account' |
29 | import { VideoPrivacy } from '@shared/models' | 27 | import { ActorModel } from '../activitypub/actor' |
30 | import { getServerActor } from '@server/models/application/application' | 28 | import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils' |
29 | import { VideoModel } from './video' | ||
30 | import { VideoChannelModel } from './video-channel' | ||
31 | 31 | ||
32 | enum ScopeNames { | 32 | enum 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 | ||