aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-comment.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/video-comment.ts')
-rw-r--r--server/lib/video-comment.ts24
1 files changed, 13 insertions, 11 deletions
diff --git a/server/lib/video-comment.ts b/server/lib/video-comment.ts
index edb72d4e2..e3fe26e35 100644
--- a/server/lib/video-comment.ts
+++ b/server/lib/video-comment.ts
@@ -1,19 +1,20 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { ResultList } from '../../shared/models' 2import { ResultList } from '../../shared/models'
3import { VideoCommentThread } 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 } from './activitypub'
7 7
8async function createVideoComment (obj: { 8async function createVideoComment (obj: {
9 text: string, 9 text: string,
10 inReplyToComment: number, 10 inReplyToCommentId: number,
11 video: VideoModel 11 video: VideoModel
12 actorId: number 12 accountId: number
13}, t: Sequelize.Transaction) { 13}, t: Sequelize.Transaction) {
14 let originCommentId: number = null 14 let originCommentId: number = null
15 if (obj.inReplyToComment) { 15
16 const repliedComment = await VideoCommentModel.loadById(obj.inReplyToComment) 16 if (obj.inReplyToCommentId) {
17 const repliedComment = await VideoCommentModel.loadById(obj.inReplyToCommentId)
17 if (!repliedComment) throw new Error('Unknown replied comment.') 18 if (!repliedComment) throw new Error('Unknown replied comment.')
18 19
19 originCommentId = repliedComment.originCommentId || repliedComment.id 20 originCommentId = repliedComment.originCommentId || repliedComment.id
@@ -22,22 +23,23 @@ async function createVideoComment (obj: {
22 const comment = await VideoCommentModel.create({ 23 const comment = await VideoCommentModel.create({
23 text: obj.text, 24 text: obj.text,
24 originCommentId, 25 originCommentId,
25 inReplyToComment: obj.inReplyToComment, 26 inReplyToCommentId: obj.inReplyToCommentId,
26 videoId: obj.video.id, 27 videoId: obj.video.id,
27 actorId: obj.actorId 28 accountId: obj.accountId,
28 }, { transaction: t }) 29 url: 'fake url'
30 }, { transaction: t, validate: false })
29 31
30 comment.set('url', getVideoCommentActivityPubUrl(obj.video, comment)) 32 comment.set('url', getVideoCommentActivityPubUrl(obj.video, comment))
31 33
32 return comment.save({ transaction: t }) 34 return comment.save({ transaction: t })
33} 35}
34 36
35function buildFormattedCommentTree (resultList: ResultList<VideoCommentModel>): VideoCommentThread { 37function buildFormattedCommentTree (resultList: ResultList<VideoCommentModel>): VideoCommentThreadTree {
36 // Comments are sorted by id ASC 38 // Comments are sorted by id ASC
37 const comments = resultList.data 39 const comments = resultList.data
38 40
39 const comment = comments.shift() 41 const comment = comments.shift()
40 const thread: VideoCommentThread = { 42 const thread: VideoCommentThreadTree = {
41 comment: comment.toFormattedJSON(), 43 comment: comment.toFormattedJSON(),
42 children: [] 44 children: []
43 } 45 }
@@ -48,7 +50,7 @@ function buildFormattedCommentTree (resultList: ResultList<VideoCommentModel>):
48 while (comments.length !== 0) { 50 while (comments.length !== 0) {
49 const childComment = comments.shift() 51 const childComment = comments.shift()
50 52
51 const childCommentThread: VideoCommentThread = { 53 const childCommentThread: VideoCommentThreadTree = {
52 comment: childComment.toFormattedJSON(), 54 comment: childComment.toFormattedJSON(),
53 children: [] 55 children: []
54 } 56 }