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.ts32
1 files changed, 31 insertions, 1 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 8e84bfc06..25cd6d563 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -3,6 +3,7 @@ import {
3 AfterDestroy, AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, IFindOptions, Is, Model, Scopes, Table, 3 AfterDestroy, AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, IFindOptions, Is, Model, Scopes, Table,
4 UpdatedAt 4 UpdatedAt
5} from 'sequelize-typescript' 5} from 'sequelize-typescript'
6import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object'
6import { VideoComment } from '../../../shared/models/videos/video-comment.model' 7import { VideoComment } from '../../../shared/models/videos/video-comment.model'
7import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub' 8import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub'
8import { CONSTRAINTS_FIELDS } from '../../initializers' 9import { CONSTRAINTS_FIELDS } from '../../initializers'
@@ -11,7 +12,8 @@ import { getSort, throwIfNotValid } from '../utils'
11import { VideoModel } from './video' 12import { VideoModel } from './video'
12 13
13enum ScopeNames { 14enum ScopeNames {
14 WITH_ACCOUNT = 'WITH_ACCOUNT' 15 WITH_ACCOUNT = 'WITH_ACCOUNT',
16 WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO'
15} 17}
16 18
17@Scopes({ 19@Scopes({
@@ -19,6 +21,14 @@ enum ScopeNames {
19 include: [ 21 include: [
20 () => AccountModel 22 () => AccountModel
21 ] 23 ]
24 },
25 [ScopeNames.WITH_IN_REPLY_TO]: {
26 include: [
27 {
28 model: () => VideoCommentModel,
29 as: 'InReplyTo'
30 }
31 ]
22 } 32 }
23}) 33})
24@Table({ 34@Table({
@@ -68,6 +78,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
68 foreignKey: { 78 foreignKey: {
69 allowNull: true 79 allowNull: true
70 }, 80 },
81 as: 'InReplyTo',
71 onDelete: 'CASCADE' 82 onDelete: 'CASCADE'
72 }) 83 })
73 InReplyToVideoComment: VideoCommentModel 84 InReplyToVideoComment: VideoCommentModel
@@ -180,4 +191,23 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
180 } 191 }
181 } as VideoComment 192 } as VideoComment
182 } 193 }
194
195 toActivityPubObject (): VideoCommentObject {
196 let inReplyTo: string
197 // New thread, so in AS we reply to the video
198 if (this.inReplyToCommentId === null) {
199 inReplyTo = this.Video.url
200 } else {
201 inReplyTo = this.InReplyToVideoComment.url
202 }
203
204 return {
205 type: 'Note' as 'Note',
206 id: this.url,
207 content: this.text,
208 inReplyTo,
209 published: this.createdAt.toISOString(),
210 url: this.url
211 }
212 }
183} 213}