diff options
Diffstat (limited to 'server/lib/activitypub/process/process-create.ts')
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 47 |
1 files changed, 9 insertions, 38 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index e8f5ade06..75f07d131 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -9,7 +9,7 @@ import { ActorModel } from '../../../models/activitypub/actor' | |||
9 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 9 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
10 | import { VideoCommentModel } from '../../../models/video/video-comment' | 10 | import { VideoCommentModel } from '../../../models/video/video-comment' |
11 | import { getOrCreateActorAndServerAndModel } from '../actor' | 11 | import { getOrCreateActorAndServerAndModel } from '../actor' |
12 | import { resolveThread } from '../video-comments' | 12 | import { addVideoComment, resolveThread } from '../video-comments' |
13 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | 13 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' |
14 | import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils' | 14 | import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils' |
15 | 15 | ||
@@ -120,48 +120,19 @@ async function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateDat | |||
120 | } | 120 | } |
121 | 121 | ||
122 | async function processCreateVideoComment (byActor: ActorModel, activity: ActivityCreate) { | 122 | async function processCreateVideoComment (byActor: ActorModel, activity: ActivityCreate) { |
123 | const comment = activity.object as VideoCommentObject | 123 | const commentObject = activity.object as VideoCommentObject |
124 | const byAccount = byActor.Account | 124 | const byAccount = byActor.Account |
125 | 125 | ||
126 | if (!byAccount) throw new Error('Cannot create video comment with the non account actor ' + byActor.url) | 126 | if (!byAccount) throw new Error('Cannot create video comment with the non account actor ' + byActor.url) |
127 | 127 | ||
128 | const { video, parents } = await resolveThread(comment.inReplyTo) | 128 | const { video } = await resolveThread(commentObject.inReplyTo) |
129 | 129 | ||
130 | return sequelizeTypescript.transaction(async t => { | 130 | const { created } = await addVideoComment(video, commentObject.id) |
131 | let originCommentId = null | ||
132 | let inReplyToCommentId = null | ||
133 | |||
134 | if (parents.length !== 0) { | ||
135 | const parent = parents[0] | ||
136 | |||
137 | originCommentId = parent.getThreadId() | ||
138 | inReplyToCommentId = parent.id | ||
139 | } | ||
140 | |||
141 | // This is a new thread | ||
142 | const objectToCreate = { | ||
143 | url: comment.id, | ||
144 | text: comment.content, | ||
145 | originCommentId, | ||
146 | inReplyToCommentId, | ||
147 | videoId: video.id, | ||
148 | accountId: byAccount.id | ||
149 | } | ||
150 | |||
151 | const options = { | ||
152 | where: { | ||
153 | url: objectToCreate.url | ||
154 | }, | ||
155 | defaults: objectToCreate, | ||
156 | transaction: t | ||
157 | } | ||
158 | const [ ,created ] = await VideoCommentModel.findOrCreate(options) | ||
159 | 131 | ||
160 | if (video.isOwned() && created === true) { | 132 | if (video.isOwned() && created === true) { |
161 | // Don't resend the activity to the sender | 133 | // Don't resend the activity to the sender |
162 | const exceptions = [ byActor ] | 134 | const exceptions = [ byActor ] |
163 | 135 | ||
164 | await forwardVideoRelatedActivity(activity, t, exceptions, video) | 136 | await forwardVideoRelatedActivity(activity, undefined, exceptions, video) |
165 | } | 137 | } |
166 | }) | ||
167 | } | 138 | } |