aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-comment.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-27 10:39:31 +0100
committerChocobozzz <me@florianbigard.com>2017-12-27 10:39:31 +0100
commitea44f375f5d3da06ca0aebfe871b9f924a26ec29 (patch)
treead2e3a458fdbeb11fae8b2215e0619df1aa6e20c /server/lib/video-comment.ts
parente2e22e40f91018cfaf244e0df9a4a93e4f6d0502 (diff)
downloadPeerTube-ea44f375f5d3da06ca0aebfe871b9f924a26ec29.tar.gz
PeerTube-ea44f375f5d3da06ca0aebfe871b9f924a26ec29.tar.zst
PeerTube-ea44f375f5d3da06ca0aebfe871b9f924a26ec29.zip
Send video comment comments to followers/origin
Diffstat (limited to 'server/lib/video-comment.ts')
-rw-r--r--server/lib/video-comment.ts26
1 files changed, 17 insertions, 9 deletions
diff --git a/server/lib/video-comment.ts b/server/lib/video-comment.ts
index e3fe26e35..ef6a8f097 100644
--- a/server/lib/video-comment.ts
+++ b/server/lib/video-comment.ts
@@ -3,27 +3,25 @@ import { ResultList } from '../../shared/models'
3import { VideoCommentThreadTree } from '../../shared/models/videos/video-comment.model' 3import { VideoCommentThreadTree } from '../../shared/models/videos/video-comment.model'
4import { VideoModel } from '../models/video/video' 4import { VideoModel } from '../models/video/video'
5import { VideoCommentModel } from '../models/video/video-comment' 5import { VideoCommentModel } from '../models/video/video-comment'
6import { getVideoCommentActivityPubUrl } from './activitypub' 6import { getVideoCommentActivityPubUrl, sendVideoRateChangeToFollowers } from './activitypub'
7import { sendCreateVideoCommentToOrigin, sendCreateVideoCommentToVideoFollowers } from './activitypub/send'
7 8
8async function createVideoComment (obj: { 9async function createVideoComment (obj: {
9 text: string, 10 text: string,
10 inReplyToCommentId: number, 11 inReplyToComment: VideoCommentModel,
11 video: VideoModel 12 video: VideoModel
12 accountId: number 13 accountId: number
13}, t: Sequelize.Transaction) { 14}, t: Sequelize.Transaction) {
14 let originCommentId: number = null 15 let originCommentId: number = null
15 16
16 if (obj.inReplyToCommentId) { 17 if (obj.inReplyToComment) {
17 const repliedComment = await VideoCommentModel.loadById(obj.inReplyToCommentId) 18 originCommentId = obj.inReplyToComment.originCommentId || obj.inReplyToComment.id
18 if (!repliedComment) throw new Error('Unknown replied comment.')
19
20 originCommentId = repliedComment.originCommentId || repliedComment.id
21 } 19 }
22 20
23 const comment = await VideoCommentModel.create({ 21 const comment = await VideoCommentModel.create({
24 text: obj.text, 22 text: obj.text,
25 originCommentId, 23 originCommentId,
26 inReplyToCommentId: obj.inReplyToCommentId, 24 inReplyToCommentId: obj.inReplyToComment.id,
27 videoId: obj.video.id, 25 videoId: obj.video.id,
28 accountId: obj.accountId, 26 accountId: obj.accountId,
29 url: 'fake url' 27 url: 'fake url'
@@ -31,7 +29,17 @@ async function createVideoComment (obj: {
31 29
32 comment.set('url', getVideoCommentActivityPubUrl(obj.video, comment)) 30 comment.set('url', getVideoCommentActivityPubUrl(obj.video, comment))
33 31
34 return comment.save({ transaction: t }) 32 const savedComment = await comment.save({ transaction: t })
33 savedComment.InReplyToVideoComment = obj.inReplyToComment
34 savedComment.Video = obj.video
35
36 if (savedComment.Video.isOwned()) {
37 await sendCreateVideoCommentToVideoFollowers(savedComment, t)
38 } else {
39 await sendCreateVideoCommentToOrigin(savedComment, t)
40 }
41
42 return savedComment
35} 43}
36 44
37function buildFormattedCommentTree (resultList: ResultList<VideoCommentModel>): VideoCommentThreadTree { 45function buildFormattedCommentTree (resultList: ResultList<VideoCommentModel>): VideoCommentThreadTree {