diff options
author | Chocobozzz <me@florianbigard.com> | 2020-11-20 11:21:08 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-11-20 11:21:08 +0100 |
commit | de94ac86a211dec657332d964693857ec235ce40 (patch) | |
tree | 3bff96a40e7c862d83561a26249992b07331b0a2 /server/lib/activitypub/process/process-dislike.ts | |
parent | 3fba4b6bce69247b1d37f923894d8f44818a891c (diff) | |
download | PeerTube-de94ac86a211dec657332d964693857ec235ce40.tar.gz PeerTube-de94ac86a211dec657332d964693857ec235ce40.tar.zst PeerTube-de94ac86a211dec657332d964693857ec235ce40.zip |
Fix incorrect IDs in AP federation
Diffstat (limited to 'server/lib/activitypub/process/process-dislike.ts')
-rw-r--r-- | server/lib/activitypub/process/process-dislike.ts | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts index 0cd204501..635c8bfcc 100644 --- a/server/lib/activitypub/process/process-dislike.ts +++ b/server/lib/activitypub/process/process-dislike.ts | |||
@@ -3,11 +3,10 @@ import { DislikeObject } from '../../../../shared/models/activitypub/objects' | |||
3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { sequelizeTypescript } from '../../../initializers/database' | 4 | import { sequelizeTypescript } from '../../../initializers/database' |
5 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 5 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
6 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | ||
7 | import { forwardVideoRelatedActivity } from '../send/utils' | ||
8 | import { getVideoDislikeActivityPubUrl } from '../url' | ||
9 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | 6 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
10 | import { MActorSignature } from '../../../types/models' | 7 | import { MActorSignature } from '../../../types/models' |
8 | import { forwardVideoRelatedActivity } from '../send/utils' | ||
9 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' | ||
11 | 10 | ||
12 | async function processDislikeActivity (options: APProcessorOptions<ActivityCreate | ActivityDislike>) { | 11 | async function processDislikeActivity (options: APProcessorOptions<ActivityCreate | ActivityDislike>) { |
13 | const { activity, byActor } = options | 12 | const { activity, byActor } = options |
@@ -23,7 +22,10 @@ export { | |||
23 | // --------------------------------------------------------------------------- | 22 | // --------------------------------------------------------------------------- |
24 | 23 | ||
25 | async function processDislike (activity: ActivityCreate | ActivityDislike, byActor: MActorSignature) { | 24 | async function processDislike (activity: ActivityCreate | ActivityDislike, byActor: MActorSignature) { |
26 | const dislikeObject = activity.type === 'Dislike' ? activity.object : (activity.object as DislikeObject).object | 25 | const dislikeObject = activity.type === 'Dislike' |
26 | ? activity.object | ||
27 | : (activity.object as DislikeObject).object | ||
28 | |||
27 | const byAccount = byActor.Account | 29 | const byAccount = byActor.Account |
28 | 30 | ||
29 | if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) | 31 | if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) |
@@ -31,9 +33,7 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct | |||
31 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) | 33 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) |
32 | 34 | ||
33 | return sequelizeTypescript.transaction(async t => { | 35 | return sequelizeTypescript.transaction(async t => { |
34 | const url = getVideoDislikeActivityPubUrl(byActor, video) | 36 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id) |
35 | |||
36 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) | ||
37 | if (existingRate && existingRate.type === 'dislike') return | 37 | if (existingRate && existingRate.type === 'dislike') return |
38 | 38 | ||
39 | await video.increment('dislikes', { transaction: t }) | 39 | await video.increment('dislikes', { transaction: t }) |
@@ -46,7 +46,7 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct | |||
46 | rate.type = 'dislike' | 46 | rate.type = 'dislike' |
47 | rate.videoId = video.id | 47 | rate.videoId = video.id |
48 | rate.accountId = byAccount.id | 48 | rate.accountId = byAccount.id |
49 | rate.url = url | 49 | rate.url = activity.id |
50 | 50 | ||
51 | await rate.save({ transaction: t }) | 51 | await rate.save({ transaction: t }) |
52 | 52 | ||