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-undo.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-undo.ts')
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index 9cad59233..5a770bb97 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts | |||
@@ -7,8 +7,8 @@ import { AccountModel } from '../../../models/account/account' | |||
7 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 7 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
8 | import { ActorModel } from '../../../models/activitypub/actor' | 8 | import { ActorModel } from '../../../models/activitypub/actor' |
9 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 9 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
10 | import { VideoModel } from '../../../models/video/video' | ||
11 | import { forwardActivity } from '../send/misc' | 10 | import { forwardActivity } from '../send/misc' |
11 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | ||
12 | 12 | ||
13 | async function processUndoActivity (activity: ActivityUndo) { | 13 | async function processUndoActivity (activity: ActivityUndo) { |
14 | const activityToUndo = activity.object | 14 | const activityToUndo = activity.object |
@@ -43,16 +43,15 @@ function processUndoLike (actorUrl: string, activity: ActivityUndo) { | |||
43 | return retryTransactionWrapper(undoLike, options) | 43 | return retryTransactionWrapper(undoLike, options) |
44 | } | 44 | } |
45 | 45 | ||
46 | function undoLike (actorUrl: string, activity: ActivityUndo) { | 46 | async function undoLike (actorUrl: string, activity: ActivityUndo) { |
47 | const likeActivity = activity.object as ActivityLike | 47 | const likeActivity = activity.object as ActivityLike |
48 | 48 | ||
49 | const { video } = await getOrCreateAccountAndVideoAndChannel(likeActivity.object) | ||
50 | |||
49 | return sequelizeTypescript.transaction(async t => { | 51 | return sequelizeTypescript.transaction(async t => { |
50 | const byAccount = await AccountModel.loadByUrl(actorUrl, t) | 52 | const byAccount = await AccountModel.loadByUrl(actorUrl, t) |
51 | if (!byAccount) throw new Error('Unknown account ' + actorUrl) | 53 | if (!byAccount) throw new Error('Unknown account ' + actorUrl) |
52 | 54 | ||
53 | const video = await VideoModel.loadByUrlAndPopulateAccount(likeActivity.object, t) | ||
54 | if (!video) throw new Error('Unknown video ' + likeActivity.actor) | ||
55 | |||
56 | const rate = await AccountVideoRateModel.load(byAccount.id, video.id, t) | 55 | const rate = await AccountVideoRateModel.load(byAccount.id, video.id, t) |
57 | if (!rate) throw new Error(`Unknown rate by account ${byAccount.id} for video ${video.id}.`) | 56 | if (!rate) throw new Error(`Unknown rate by account ${byAccount.id} for video ${video.id}.`) |
58 | 57 | ||
@@ -76,16 +75,15 @@ function processUndoDislike (actorUrl: string, activity: ActivityUndo) { | |||
76 | return retryTransactionWrapper(undoDislike, options) | 75 | return retryTransactionWrapper(undoDislike, options) |
77 | } | 76 | } |
78 | 77 | ||
79 | function undoDislike (actorUrl: string, activity: ActivityUndo) { | 78 | async function undoDislike (actorUrl: string, activity: ActivityUndo) { |
80 | const dislike = activity.object.object as DislikeObject | 79 | const dislike = activity.object.object as DislikeObject |
81 | 80 | ||
81 | const { video } = await getOrCreateAccountAndVideoAndChannel(dislike.object) | ||
82 | |||
82 | return sequelizeTypescript.transaction(async t => { | 83 | return sequelizeTypescript.transaction(async t => { |
83 | const byAccount = await AccountModel.loadByUrl(actorUrl, t) | 84 | const byAccount = await AccountModel.loadByUrl(actorUrl, t) |
84 | if (!byAccount) throw new Error('Unknown account ' + actorUrl) | 85 | if (!byAccount) throw new Error('Unknown account ' + actorUrl) |
85 | 86 | ||
86 | const video = await VideoModel.loadByUrlAndPopulateAccount(dislike.object, t) | ||
87 | if (!video) throw new Error('Unknown video ' + dislike.actor) | ||
88 | |||
89 | const rate = await AccountVideoRateModel.load(byAccount.id, video.id, t) | 87 | const rate = await AccountVideoRateModel.load(byAccount.id, video.id, t) |
90 | if (!rate) throw new Error(`Unknown rate by account ${byAccount.id} for video ${video.id}.`) | 88 | if (!rate) throw new Error(`Unknown rate by account ${byAccount.id} for video ${video.id}.`) |
91 | 89 | ||