aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-comment.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-22 09:14:50 +0100
committerChocobozzz <me@florianbigard.com>2017-12-22 09:14:50 +0100
commit6d8524702874120a4667269a81a61e3c7c5e300d (patch)
treea462d95c56b558a4cfc42db08ec1cb66b1f99680 /server/models/video/video-comment.ts
parentfb4fd623d5e5adcfdc9ecf3dffef702b3786f486 (diff)
downloadPeerTube-6d8524702874120a4667269a81a61e3c7c5e300d.tar.gz
PeerTube-6d8524702874120a4667269a81a61e3c7c5e300d.tar.zst
PeerTube-6d8524702874120a4667269a81a61e3c7c5e300d.zip
Create comment on replied mastodon statutes
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}