diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-10 17:18:12 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-10 17:19:14 +0100 |
commit | 2ccaeeb341ffe8c2609039bf4c6d8835b4650316 (patch) | |
tree | a6bf6e05e7f02bc315e872d67a0b61ad6ad3d777 /server/lib/activitypub/process/process-like.ts | |
parent | 759f8a29e95932023564ca98dcbc90d1acb92da0 (diff) | |
download | PeerTube-2ccaeeb341ffe8c2609039bf4c6d8835b4650316.tar.gz PeerTube-2ccaeeb341ffe8c2609039bf4c6d8835b4650316.tar.zst PeerTube-2ccaeeb341ffe8c2609039bf4c6d8835b4650316.zip |
Fetch remote AP objects
Diffstat (limited to 'server/lib/activitypub/process/process-like.ts')
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts index 77fadabe1..0d161b126 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts | |||
@@ -3,9 +3,9 @@ import { retryTransactionWrapper } from '../../../helpers/database-utils' | |||
3 | import { sequelizeTypescript } from '../../../initializers' | 3 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
6 | import { VideoModel } from '../../../models/video/video' | ||
7 | import { getOrCreateActorAndServerAndModel } from '../actor' | 6 | import { getOrCreateActorAndServerAndModel } from '../actor' |
8 | import { forwardActivity } from '../send/misc' | 7 | import { forwardActivity } from '../send/misc' |
8 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | ||
9 | 9 | ||
10 | async function processLikeActivity (activity: ActivityLike) { | 10 | async function processLikeActivity (activity: ActivityLike) { |
11 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) | 11 | const actor = await getOrCreateActorAndServerAndModel(activity.actor) |
@@ -30,17 +30,15 @@ async function processLikeVideo (actor: ActorModel, activity: ActivityLike) { | |||
30 | return retryTransactionWrapper(createVideoLike, options) | 30 | return retryTransactionWrapper(createVideoLike, options) |
31 | } | 31 | } |
32 | 32 | ||
33 | function createVideoLike (byActor: ActorModel, activity: ActivityLike) { | 33 | async function createVideoLike (byActor: ActorModel, activity: ActivityLike) { |
34 | const videoUrl = activity.object | 34 | const videoUrl = activity.object |
35 | 35 | ||
36 | const byAccount = byActor.Account | 36 | const byAccount = byActor.Account |
37 | if (!byAccount) throw new Error('Cannot create like with the non account actor ' + byActor.url) | 37 | if (!byAccount) throw new Error('Cannot create like with the non account actor ' + byActor.url) |
38 | 38 | ||
39 | return sequelizeTypescript.transaction(async t => { | 39 | const { video } = await getOrCreateAccountAndVideoAndChannel(videoUrl) |
40 | const video = await VideoModel.loadByUrlAndPopulateAccount(videoUrl) | ||
41 | |||
42 | if (!video) throw new Error('Unknown video ' + videoUrl) | ||
43 | 40 | ||
41 | return sequelizeTypescript.transaction(async t => { | ||
44 | const rate = { | 42 | const rate = { |
45 | type: 'like' as 'like', | 43 | type: 'like' as 'like', |
46 | videoId: video.id, | 44 | videoId: video.id, |