aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-like.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/process/process-like.ts')
-rw-r--r--server/lib/activitypub/process/process-like.ts19
1 files changed, 11 insertions, 8 deletions
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts
index a6e391f1e..a7fcec21c 100644
--- a/server/lib/activitypub/process/process-like.ts
+++ b/server/lib/activitypub/process/process-like.ts
@@ -1,16 +1,16 @@
1import { ActivityLike } from '../../../../shared/models/activitypub' 1import { ActivityLike } from '../../../../shared/models/activitypub'
2import { retryTransactionWrapper } from '../../../helpers' 2import { retryTransactionWrapper } from '../../../helpers'
3import { sequelizeTypescript } from '../../../initializers' 3import { sequelizeTypescript } from '../../../initializers'
4import { AccountModel } from '../../../models/account/account'
5import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 4import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
5import { ActorModel } from '../../../models/activitypub/actor'
6import { VideoModel } from '../../../models/video/video' 6import { VideoModel } from '../../../models/video/video'
7import { getOrCreateAccountAndServer } from '../account' 7import { getOrCreateActorAndServerAndModel } from '../actor'
8import { forwardActivity } from '../send/misc' 8import { forwardActivity } from '../send/misc'
9 9
10async function processLikeActivity (activity: ActivityLike) { 10async function processLikeActivity (activity: ActivityLike) {
11 const account = await getOrCreateAccountAndServer(activity.actor) 11 const actor = await getOrCreateActorAndServerAndModel(activity.actor)
12 12
13 return processLikeVideo(account, activity) 13 return processLikeVideo(actor, activity)
14} 14}
15 15
16// --------------------------------------------------------------------------- 16// ---------------------------------------------------------------------------
@@ -21,18 +21,21 @@ export {
21 21
22// --------------------------------------------------------------------------- 22// ---------------------------------------------------------------------------
23 23
24async function processLikeVideo (byAccount: AccountModel, activity: ActivityLike) { 24async function processLikeVideo (actor: ActorModel, activity: ActivityLike) {
25 const options = { 25 const options = {
26 arguments: [ byAccount, activity ], 26 arguments: [ actor, activity ],
27 errorMessage: 'Cannot like the video with many retries.' 27 errorMessage: 'Cannot like the video with many retries.'
28 } 28 }
29 29
30 return retryTransactionWrapper(createVideoLike, options) 30 return retryTransactionWrapper(createVideoLike, options)
31} 31}
32 32
33function createVideoLike (byAccount: AccountModel, activity: ActivityLike) { 33function createVideoLike (byActor: ActorModel, activity: ActivityLike) {
34 const videoUrl = activity.object 34 const videoUrl = activity.object
35 35
36 const byAccount = byActor.Account
37 if (!byAccount) throw new Error('Cannot create like with the non account actor ' + byActor.url)
38
36 return sequelizeTypescript.transaction(async t => { 39 return sequelizeTypescript.transaction(async t => {
37 const video = await VideoModel.loadByUrlAndPopulateAccount(videoUrl) 40 const video = await VideoModel.loadByUrlAndPopulateAccount(videoUrl)
38 41
@@ -52,7 +55,7 @@ function createVideoLike (byAccount: AccountModel, activity: ActivityLike) {
52 55
53 if (video.isOwned() && created === true) { 56 if (video.isOwned() && created === true) {
54 // Don't resend the activity to the sender 57 // Don't resend the activity to the sender
55 const exceptions = [ byAccount ] 58 const exceptions = [ byActor ]
56 await forwardActivity(activity, t, exceptions) 59 await forwardActivity(activity, t, exceptions)
57 } 60 }
58 }) 61 })