diff options
Diffstat (limited to 'server/models/video/video-comment.ts')
-rw-r--r-- | server/models/video/video-comment.ts | 32 |
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' |
6 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' | ||
6 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' | 7 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' |
7 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub' | 8 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub' |
8 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 9 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
@@ -11,7 +12,8 @@ import { getSort, throwIfNotValid } from '../utils' | |||
11 | import { VideoModel } from './video' | 12 | import { VideoModel } from './video' |
12 | 13 | ||
13 | enum ScopeNames { | 14 | enum 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 | } |