aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorJulien Maulny <julien.maulny@protonmail.com>2019-11-15 19:05:08 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-12-04 09:36:45 +0100
commit69222afac8f8c41d90295b33f0695bbff352851e (patch)
tree63fe1faea94dd3bfc54e633631eecb275c969e54 /server/models/video
parent69c7f7525ddf13b7ced787d8b72ac74b43665517 (diff)
downloadPeerTube-69222afac8f8c41d90295b33f0695bbff352851e.tar.gz
PeerTube-69222afac8f8c41d90295b33f0695bbff352851e.tar.zst
PeerTube-69222afac8f8c41d90295b33f0695bbff352851e.zip
Soft delete video comments instead of detroy
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-comment.ts33
1 files changed, 29 insertions, 4 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 2e4220434..b44d65138 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -1,5 +1,5 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' 1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
2import { ActivityTagObject } from '../../../shared/models/activitypub/objects/common-objects' 2import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects'
3import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' 3import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object'
4import { VideoComment } from '../../../shared/models/videos/video-comment.model' 4import { VideoComment } from '../../../shared/models/videos/video-comment.model'
5import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 5import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
@@ -122,6 +122,10 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
122 @UpdatedAt 122 @UpdatedAt
123 updatedAt: Date 123 updatedAt: Date
124 124
125 @AllowNull(true)
126 @Column(DataType.DATE)
127 deletedAt: Date
128
125 @AllowNull(false) 129 @AllowNull(false)
126 @Is('VideoCommentUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) 130 @Is('VideoCommentUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
127 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max)) 131 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max))
@@ -177,7 +181,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
177 181
178 @BelongsTo(() => AccountModel, { 182 @BelongsTo(() => AccountModel, {
179 foreignKey: { 183 foreignKey: {
180 allowNull: false 184 allowNull: true
181 }, 185 },
182 onDelete: 'CASCADE' 186 onDelete: 'CASCADE'
183 }) 187 })
@@ -436,9 +440,17 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
436 } 440 }
437 441
438 isOwned () { 442 isOwned () {
443 if (!this.Account) {
444 return false
445 }
446
439 return this.Account.isOwned() 447 return this.Account.isOwned()
440 } 448 }
441 449
450 isDeleted () {
451 return null !== this.deletedAt
452 }
453
442 extractMentions () { 454 extractMentions () {
443 let result: string[] = [] 455 let result: string[] = []
444 456
@@ -487,12 +499,25 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
487 videoId: this.videoId, 499 videoId: this.videoId,
488 createdAt: this.createdAt, 500 createdAt: this.createdAt,
489 updatedAt: this.updatedAt, 501 updatedAt: this.updatedAt,
502 deletedAt: this.deletedAt,
503 isDeleted: this.isDeleted(),
490 totalReplies: this.get('totalReplies') || 0, 504 totalReplies: this.get('totalReplies') || 0,
491 account: this.Account.toFormattedJSON() 505 account: this.Account ? this.Account.toFormattedJSON() : null
492 } as VideoComment 506 } as VideoComment
493 } 507 }
494 508
495 toActivityPubObject (this: MCommentAP, threadParentComments: MCommentOwner[]): VideoCommentObject { 509 toActivityPubObject (this: MCommentAP, threadParentComments: MCommentOwner[]): VideoCommentObject | ActivityTombstoneObject {
510 if (this.isDeleted()) {
511 return {
512 id: this.url,
513 type: 'Tombstone',
514 formerType: 'Note',
515 published: this.createdAt.toISOString(),
516 updated: this.updatedAt.toISOString(),
517 deleted: this.deletedAt.toISOString()
518 }
519 }
520
496 let inReplyTo: string 521 let inReplyTo: string
497 // New thread, so in AS we reply to the video 522 // New thread, so in AS we reply to the video
498 if (this.inReplyToCommentId === null) { 523 if (this.inReplyToCommentId === null) {