diff options
Diffstat (limited to 'server/lib/activitypub/process/process-dislike.ts')
-rw-r--r-- | server/lib/activitypub/process/process-dislike.ts | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts deleted file mode 100644 index 4e270f917..000000000 --- a/server/lib/activitypub/process/process-dislike.ts +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | import { VideoModel } from '@server/models/video/video' | ||
2 | import { ActivityDislike } from '@shared/models' | ||
3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | ||
4 | import { sequelizeTypescript } from '../../../initializers/database' | ||
5 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | ||
6 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | ||
7 | import { MActorSignature } from '../../../types/models' | ||
8 | import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos' | ||
9 | |||
10 | async function processDislikeActivity (options: APProcessorOptions<ActivityDislike>) { | ||
11 | const { activity, byActor } = options | ||
12 | return retryTransactionWrapper(processDislike, activity, byActor) | ||
13 | } | ||
14 | |||
15 | // --------------------------------------------------------------------------- | ||
16 | |||
17 | export { | ||
18 | processDislikeActivity | ||
19 | } | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | |||
23 | async function processDislike (activity: ActivityDislike, byActor: MActorSignature) { | ||
24 | const dislikeObject = activity.object | ||
25 | const byAccount = byActor.Account | ||
26 | |||
27 | if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) | ||
28 | |||
29 | const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: dislikeObject, fetchType: 'only-video' }) | ||
30 | |||
31 | // We don't care about dislikes of remote videos | ||
32 | if (!onlyVideo.isOwned()) return | ||
33 | |||
34 | return sequelizeTypescript.transaction(async t => { | ||
35 | const video = await VideoModel.loadFull(onlyVideo.id, t) | ||
36 | |||
37 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t) | ||
38 | if (existingRate && existingRate.type === 'dislike') return | ||
39 | |||
40 | await video.increment('dislikes', { transaction: t }) | ||
41 | video.dislikes++ | ||
42 | |||
43 | if (existingRate && existingRate.type === 'like') { | ||
44 | await video.decrement('likes', { transaction: t }) | ||
45 | video.likes-- | ||
46 | } | ||
47 | |||
48 | const rate = existingRate || new AccountVideoRateModel() | ||
49 | rate.type = 'dislike' | ||
50 | rate.videoId = video.id | ||
51 | rate.accountId = byAccount.id | ||
52 | rate.url = activity.id | ||
53 | |||
54 | await rate.save({ transaction: t }) | ||
55 | |||
56 | await federateVideoIfNeeded(video, false, t) | ||
57 | }) | ||
58 | } | ||