diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-14 17:38:41 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-19 10:53:16 +0100 |
commit | 50d6de9c286abcb34ff4234d56d9cbb803db7665 (patch) | |
tree | f1732b27edcd05c7877a8358b8312f1e38c287ed /server/lib/activitypub/process/process-like.ts | |
parent | fadf619ad61a016c1c7fc53de5a8f398a4f77519 (diff) | |
download | PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.gz PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.zst PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.zip |
Begin moving video channel to actor
Diffstat (limited to 'server/lib/activitypub/process/process-like.ts')
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 19 |
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 @@ | |||
1 | import { ActivityLike } from '../../../../shared/models/activitypub' | 1 | import { ActivityLike } from '../../../../shared/models/activitypub' |
2 | import { retryTransactionWrapper } from '../../../helpers' | 2 | import { retryTransactionWrapper } from '../../../helpers' |
3 | import { sequelizeTypescript } from '../../../initializers' | 3 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { AccountModel } from '../../../models/account/account' | ||
5 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | ||
6 | import { VideoModel } from '../../../models/video/video' | 6 | import { VideoModel } from '../../../models/video/video' |
7 | import { getOrCreateAccountAndServer } from '../account' | 7 | import { getOrCreateActorAndServerAndModel } from '../actor' |
8 | import { forwardActivity } from '../send/misc' | 8 | import { forwardActivity } from '../send/misc' |
9 | 9 | ||
10 | async function processLikeActivity (activity: ActivityLike) { | 10 | async 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 | ||
24 | async function processLikeVideo (byAccount: AccountModel, activity: ActivityLike) { | 24 | async 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 | ||
33 | function createVideoLike (byAccount: AccountModel, activity: ActivityLike) { | 33 | function 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 | }) |