From ea44f375f5d3da06ca0aebfe871b9f924a26ec29 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 27 Dec 2017 10:39:31 +0100 Subject: Send video comment comments to followers/origin --- server/models/video/video-comment.ts | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'server/models') 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 { AfterDestroy, AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, IFindOptions, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' +import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' import { VideoComment } from '../../../shared/models/videos/video-comment.model' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub' import { CONSTRAINTS_FIELDS } from '../../initializers' @@ -11,7 +12,8 @@ import { getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' enum ScopeNames { - WITH_ACCOUNT = 'WITH_ACCOUNT' + WITH_ACCOUNT = 'WITH_ACCOUNT', + WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO' } @Scopes({ @@ -19,6 +21,14 @@ enum ScopeNames { include: [ () => AccountModel ] + }, + [ScopeNames.WITH_IN_REPLY_TO]: { + include: [ + { + model: () => VideoCommentModel, + as: 'InReplyTo' + } + ] } }) @Table({ @@ -68,6 +78,7 @@ export class VideoCommentModel extends Model { foreignKey: { allowNull: true }, + as: 'InReplyTo', onDelete: 'CASCADE' }) InReplyToVideoComment: VideoCommentModel @@ -180,4 +191,23 @@ export class VideoCommentModel extends Model { } } as VideoComment } + + toActivityPubObject (): VideoCommentObject { + let inReplyTo: string + // New thread, so in AS we reply to the video + if (this.inReplyToCommentId === null) { + inReplyTo = this.Video.url + } else { + inReplyTo = this.InReplyToVideoComment.url + } + + return { + type: 'Note' as 'Note', + id: this.url, + content: this.text, + inReplyTo, + published: this.createdAt.toISOString(), + url: this.url + } + } } -- cgit v1.2.3