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.ts25
1 files changed, 16 insertions, 9 deletions
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts
index d77b30f24..0347f95be 100644
--- a/server/lib/activitypub/process/process-like.ts
+++ b/server/lib/activitypub/process/process-like.ts
@@ -1,14 +1,14 @@
1import { ActivityLike } from '../../../../shared/models/activitypub/activity' 1import { ActivityLike } from '../../../../shared/models/activitypub/activity'
2import { retryTransactionWrapper } from '../../../helpers/database-utils'
2import { database as db } from '../../../initializers' 3import { database as db } from '../../../initializers'
3import { AccountInstance } from '../../../models/account/account-interface' 4import { AccountInstance } from '../../../models/account/account-interface'
4import { getOrCreateAccountAndServer } from '../account' 5import { getOrCreateAccountAndServer } from '../account'
5import { sendLikeToVideoFollowers } from '../send/send-like' 6import { forwardActivity } from '../send/misc'
6import { retryTransactionWrapper } from '../../../helpers/database-utils'
7 7
8async function processLikeActivity (activity: ActivityLike) { 8async function processLikeActivity (activity: ActivityLike) {
9 const account = await getOrCreateAccountAndServer(activity.actor) 9 const account = await getOrCreateAccountAndServer(activity.actor)
10 10
11 return processLikeVideo(account, activity.object) 11 return processLikeVideo(account, activity)
12} 12}
13 13
14// --------------------------------------------------------------------------- 14// ---------------------------------------------------------------------------
@@ -19,16 +19,18 @@ export {
19 19
20// --------------------------------------------------------------------------- 20// ---------------------------------------------------------------------------
21 21
22async function processLikeVideo (byAccount: AccountInstance, videoUrl: string) { 22async function processLikeVideo (byAccount: AccountInstance, activity: ActivityLike) {
23 const options = { 23 const options = {
24 arguments: [ byAccount, videoUrl ], 24 arguments: [ byAccount, activity ],
25 errorMessage: 'Cannot like the video with many retries.' 25 errorMessage: 'Cannot like the video with many retries.'
26 } 26 }
27 27
28 return retryTransactionWrapper(createVideoLike, options) 28 return retryTransactionWrapper(createVideoLike, options)
29} 29}
30 30
31function createVideoLike (byAccount: AccountInstance, videoUrl: string) { 31function createVideoLike (byAccount: AccountInstance, activity: ActivityLike) {
32 const videoUrl = activity.object
33
32 return db.sequelize.transaction(async t => { 34 return db.sequelize.transaction(async t => {
33 const video = await db.Video.loadByUrlAndPopulateAccount(videoUrl) 35 const video = await db.Video.loadByUrlAndPopulateAccount(videoUrl)
34 36
@@ -41,10 +43,15 @@ function createVideoLike (byAccount: AccountInstance, videoUrl: string) {
41 } 43 }
42 const [ , created ] = await db.AccountVideoRate.findOrCreate({ 44 const [ , created ] = await db.AccountVideoRate.findOrCreate({
43 where: rate, 45 where: rate,
44 defaults: rate 46 defaults: rate,
47 transaction: t
45 }) 48 })
46 await video.increment('likes') 49 await video.increment('likes', { transaction: t })
47 50
48 if (video.isOwned() && created === true) await sendLikeToVideoFollowers(byAccount, video, undefined) 51 if (video.isOwned() && created === true) {
52 // Don't resend the activity to the sender
53 const exceptions = [ byAccount ]
54 await forwardActivity(activity, t, exceptions)
55 }
49 }) 56 })
50} 57}