aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-comment.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-comment.ts')
-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) {