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.ts95
1 files changed, 95 insertions, 0 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
new file mode 100644
index 000000000..92c0c6112
--- /dev/null
+++ b/server/models/video/video-comment.ts
@@ -0,0 +1,95 @@
1import * as Sequelize from 'sequelize'
2import {
3 AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, IFindOptions, Is, IsUUID, Model, Table,
4 UpdatedAt
5} from 'sequelize-typescript'
6import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub'
7import { CONSTRAINTS_FIELDS } from '../../initializers'
8import { ActorModel } from '../activitypub/actor'
9import { throwIfNotValid } from '../utils'
10import { VideoModel } from './video'
11
12@Table({
13 tableName: 'videoComment',
14 indexes: [
15 {
16 fields: [ 'videoId' ]
17 }
18 ]
19})
20export 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}