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.ts41
1 files changed, 39 insertions, 2 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 66fca2484..dbb2fe429 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 { ActivityTagObject } from '../../../shared/models/activitypub/objects/common-objects'
6import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' 7import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object'
7import { VideoComment } from '../../../shared/models/videos/video-comment.model' 8import { VideoComment } from '../../../shared/models/videos/video-comment.model'
8import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 9import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
@@ -270,6 +271,30 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
270 }) 271 })
271 } 272 }
272 273
274 static listThreadParentComments (comment: VideoCommentModel, t: Sequelize.Transaction) {
275 const query = {
276 order: [ [ 'createdAt', 'ASC' ] ],
277 where: {
278 [ Sequelize.Op.or ]: [
279 { id: comment.getThreadId() },
280 { originCommentId: comment.getThreadId() }
281 ],
282 id: {
283 [ Sequelize.Op.ne ]: comment.id
284 }
285 },
286 transaction: t
287 }
288
289 return VideoCommentModel
290 .scope([ ScopeNames.WITH_ACCOUNT ])
291 .findAll(query)
292 }
293
294 getThreadId (): number {
295 return this.originCommentId || this.id
296 }
297
273 isOwned () { 298 isOwned () {
274 return this.Account.isOwned() 299 return this.Account.isOwned()
275 } 300 }
@@ -289,7 +314,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
289 } as VideoComment 314 } as VideoComment
290 } 315 }
291 316
292 toActivityPubObject (): VideoCommentObject { 317 toActivityPubObject (threadParentComments: VideoCommentModel[]): VideoCommentObject {
293 let inReplyTo: string 318 let inReplyTo: string
294 // New thread, so in AS we reply to the video 319 // New thread, so in AS we reply to the video
295 if (this.inReplyToCommentId === null) { 320 if (this.inReplyToCommentId === null) {
@@ -298,6 +323,17 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
298 inReplyTo = this.InReplyToVideoComment.url 323 inReplyTo = this.InReplyToVideoComment.url
299 } 324 }
300 325
326 const tag: ActivityTagObject[] = []
327 for (const parentComment of threadParentComments) {
328 const actor = parentComment.Account.Actor
329
330 tag.push({
331 type: 'Mention',
332 href: actor.url,
333 name: `@${actor.preferredUsername}@${actor.getHost()}`
334 })
335 }
336
301 return { 337 return {
302 type: 'Note' as 'Note', 338 type: 'Note' as 'Note',
303 id: this.url, 339 id: this.url,
@@ -306,7 +342,8 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
306 updated: this.updatedAt.toISOString(), 342 updated: this.updatedAt.toISOString(),
307 published: this.createdAt.toISOString(), 343 published: this.createdAt.toISOString(),
308 url: this.url, 344 url: this.url,
309 attributedTo: this.Account.Actor.url 345 attributedTo: this.Account.Actor.url,
346 tag
310 } 347 }
311 } 348 }
312} 349}