diff options
Diffstat (limited to 'server/lib/activitypub/process/process-create.ts')
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 55 |
1 files changed, 2 insertions, 53 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index eff796c1d..ee180b765 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -1,20 +1,17 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { ActivityCreate, VideoTorrentObject } from '../../../../shared' | 1 | import { ActivityCreate, VideoTorrentObject } from '../../../../shared' |
3 | import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' | 2 | import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' |
4 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' | 3 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' |
5 | import { VideoRateType } from '../../../../shared/models/videos' | ||
6 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
7 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
8 | import { sequelizeTypescript } from '../../../initializers' | 6 | import { sequelizeTypescript } from '../../../initializers' |
9 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 7 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
10 | import { ActorModel } from '../../../models/activitypub/actor' | 8 | import { ActorModel } from '../../../models/activitypub/actor' |
11 | import { VideoModel } from '../../../models/video/video' | ||
12 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 9 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
13 | import { VideoCommentModel } from '../../../models/video/video-comment' | 10 | import { VideoCommentModel } from '../../../models/video/video-comment' |
14 | import { getOrCreateActorAndServerAndModel } from '../actor' | 11 | import { getOrCreateActorAndServerAndModel } from '../actor' |
15 | import { forwardActivity, getActorsInvolvedInVideo } from '../send/misc' | 12 | import { forwardActivity, getActorsInvolvedInVideo } from '../send/misc' |
16 | import { addVideoComments, resolveThread } from '../video-comments' | 13 | import { resolveThread } from '../video-comments' |
17 | import { addVideoShares, getOrCreateAccountAndVideoAndChannel } from '../videos' | 14 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' |
18 | 15 | ||
19 | async function processCreateActivity (activity: ActivityCreate) { | 16 | async function processCreateActivity (activity: ActivityCreate) { |
20 | const activityObject = activity.object | 17 | const activityObject = activity.object |
@@ -53,57 +50,9 @@ async function processCreateVideo ( | |||
53 | 50 | ||
54 | const { video } = await getOrCreateAccountAndVideoAndChannel(videoToCreateData, actor) | 51 | const { video } = await getOrCreateAccountAndVideoAndChannel(videoToCreateData, actor) |
55 | 52 | ||
56 | // Process outside the transaction because we could fetch remote data | ||
57 | if (videoToCreateData.likes && Array.isArray(videoToCreateData.likes.orderedItems)) { | ||
58 | logger.info('Adding likes of video %s.', video.uuid) | ||
59 | await createRates(videoToCreateData.likes.orderedItems, video, 'like') | ||
60 | } | ||
61 | |||
62 | if (videoToCreateData.dislikes && Array.isArray(videoToCreateData.dislikes.orderedItems)) { | ||
63 | logger.info('Adding dislikes of video %s.', video.uuid) | ||
64 | await createRates(videoToCreateData.dislikes.orderedItems, video, 'dislike') | ||
65 | } | ||
66 | |||
67 | if (videoToCreateData.shares && Array.isArray(videoToCreateData.shares.orderedItems)) { | ||
68 | logger.info('Adding shares of video %s.', video.uuid) | ||
69 | await addVideoShares(video, videoToCreateData.shares.orderedItems) | ||
70 | } | ||
71 | |||
72 | if (videoToCreateData.comments && Array.isArray(videoToCreateData.comments.orderedItems)) { | ||
73 | logger.info('Adding comments of video %s.', video.uuid) | ||
74 | await addVideoComments(video, videoToCreateData.comments.orderedItems) | ||
75 | } | ||
76 | |||
77 | return video | 53 | return video |
78 | } | 54 | } |
79 | 55 | ||
80 | async function createRates (actorUrls: string[], video: VideoModel, rate: VideoRateType) { | ||
81 | let rateCounts = 0 | ||
82 | const tasks: Bluebird<number>[] = [] | ||
83 | |||
84 | for (const actorUrl of actorUrls) { | ||
85 | const actor = await getOrCreateActorAndServerAndModel(actorUrl) | ||
86 | const p = AccountVideoRateModel | ||
87 | .create({ | ||
88 | videoId: video.id, | ||
89 | accountId: actor.Account.id, | ||
90 | type: rate | ||
91 | }) | ||
92 | .then(() => rateCounts += 1) | ||
93 | |||
94 | tasks.push(p) | ||
95 | } | ||
96 | |||
97 | await Promise.all(tasks) | ||
98 | |||
99 | logger.info('Adding %d %s to video %s.', rateCounts, rate, video.uuid) | ||
100 | |||
101 | // This is "likes" and "dislikes" | ||
102 | await video.increment(rate + 's', { by: rateCounts }) | ||
103 | |||
104 | return | ||
105 | } | ||
106 | |||
107 | async function processCreateDislike (byActor: ActorModel, activity: ActivityCreate) { | 56 | async function processCreateDislike (byActor: ActorModel, activity: ActivityCreate) { |
108 | const options = { | 57 | const options = { |
109 | arguments: [ byActor, activity ], | 58 | arguments: [ byActor, activity ], |