diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-24 13:41:10 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:53 +0100 |
commit | 63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd (patch) | |
tree | 3ee4b351025d4b19f6e880754df44fa7605b683d /server/lib/activitypub/process/process-like.ts | |
parent | d4f1e94c89336255537b0b82913591f00e716201 (diff) | |
download | PeerTube-63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd.tar.gz PeerTube-63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd.tar.zst PeerTube-63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd.zip |
Correctly forward like/dislikes and undo
Diffstat (limited to 'server/lib/activitypub/process/process-like.ts')
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 25 |
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 @@ | |||
1 | import { ActivityLike } from '../../../../shared/models/activitypub/activity' | 1 | import { ActivityLike } from '../../../../shared/models/activitypub/activity' |
2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | ||
2 | import { database as db } from '../../../initializers' | 3 | import { database as db } from '../../../initializers' |
3 | import { AccountInstance } from '../../../models/account/account-interface' | 4 | import { AccountInstance } from '../../../models/account/account-interface' |
4 | import { getOrCreateAccountAndServer } from '../account' | 5 | import { getOrCreateAccountAndServer } from '../account' |
5 | import { sendLikeToVideoFollowers } from '../send/send-like' | 6 | import { forwardActivity } from '../send/misc' |
6 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | ||
7 | 7 | ||
8 | async function processLikeActivity (activity: ActivityLike) { | 8 | async 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 | ||
22 | async function processLikeVideo (byAccount: AccountInstance, videoUrl: string) { | 22 | async 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 | ||
31 | function createVideoLike (byAccount: AccountInstance, videoUrl: string) { | 31 | function 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 | } |