]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/video/video-comment.ts
Create comment on replied mastodon statutes
[github/Chocobozzz/PeerTube.git] / server / models / video / video-comment.ts
1 import * as Sequelize from 'sequelize'
2 import {
3 AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, IFindOptions, Is, IsUUID, Model, Table,
4 UpdatedAt
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'
11
12 @Table({
13 tableName: 'videoComment',
14 indexes: [
15 {
16 fields: [ 'videoId' ]
17 }
18 ]
19 })
20 export class VideoCommentModel extends Model<VideoCommentModel> {
21 @CreatedAt
22 createdAt: Date
23
24 @UpdatedAt
25 updatedAt: Date
26
27 @AllowNull(false)
28 @Is('VideoCommentUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
29 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max))
30 url: string
31
32 @AllowNull(false)
33 @Column(DataType.TEXT)
34 text: string
35
36 @ForeignKey(() => VideoCommentModel)
37 @Column
38 originCommentId: number
39
40 @BelongsTo(() => VideoCommentModel, {
41 foreignKey: {
42 allowNull: true
43 },
44 onDelete: 'CASCADE'
45 })
46 OriginVideoComment: VideoCommentModel
47
48 @ForeignKey(() => VideoCommentModel)
49 @Column
50 inReplyToCommentId: number
51
52 @BelongsTo(() => VideoCommentModel, {
53 foreignKey: {
54 allowNull: true
55 },
56 onDelete: 'CASCADE'
57 })
58 InReplyToVideoComment: VideoCommentModel
59
60 @ForeignKey(() => VideoModel)
61 @Column
62 videoId: number
63
64 @BelongsTo(() => VideoModel, {
65 foreignKey: {
66 allowNull: false
67 },
68 onDelete: 'CASCADE'
69 })
70 Video: VideoModel
71
72 @ForeignKey(() => ActorModel)
73 @Column
74 actorId: number
75
76 @BelongsTo(() => ActorModel, {
77 foreignKey: {
78 allowNull: false
79 },
80 onDelete: 'CASCADE'
81 })
82 Actor: ActorModel
83
84 static loadByUrl (url: string, t?: Sequelize.Transaction) {
85 const query: IFindOptions<VideoCommentModel> = {
86 where: {
87 url
88 }
89 }
90
91 if (t !== undefined) query.transaction = t
92
93 return VideoCommentModel.findOne(query)
94 }
95 }