1 import * as Sequelize from 'sequelize'
3 AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, IFindOptions, Is, IsUUID, Model, Table,
5 } from 'sequelize-typescript'
6 import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub'
7 import { CONSTRAINTS_FIELDS } from '../../initializers'
8 import { ActorModel } from '../activitypub/actor'
9 import { throwIfNotValid } from '../utils'
10 import { VideoModel } from './video'
13 tableName: 'videoComment',
20 export class VideoCommentModel extends Model<VideoCommentModel> {
28 @Is('VideoCommentUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
29 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max))
33 @Column(DataType.TEXT)
36 @ForeignKey(() => VideoCommentModel)
38 originCommentId: number
40 @BelongsTo(() => VideoCommentModel, {
46 OriginVideoComment: VideoCommentModel
48 @ForeignKey(() => VideoCommentModel)
50 inReplyToCommentId: number
52 @BelongsTo(() => VideoCommentModel, {
58 InReplyToVideoComment: VideoCommentModel
60 @ForeignKey(() => VideoModel)
64 @BelongsTo(() => VideoModel, {
72 @ForeignKey(() => ActorModel)
76 @BelongsTo(() => ActorModel, {
84 static loadByUrl (url: string, t?: Sequelize.Transaction) {
85 const query: IFindOptions<VideoCommentModel> = {
91 if (t !== undefined) query.transaction = t
93 return VideoCommentModel.findOne(query)