diff options
Diffstat (limited to 'server/lib/activitypub/process/process-create.ts')
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 1777733a0..147bbd132 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -5,9 +5,10 @@ import { logger, retryTransactionWrapper } from '../../../helpers' | |||
5 | import { database as db } from '../../../initializers' | 5 | import { database as db } from '../../../initializers' |
6 | import { AccountInstance } from '../../../models/account/account-interface' | 6 | import { AccountInstance } from '../../../models/account/account-interface' |
7 | import { getOrCreateAccountAndServer } from '../account' | 7 | import { getOrCreateAccountAndServer } from '../account' |
8 | import { sendCreateViewToVideoFollowers } from '../send/send-create' | 8 | import { sendCreateDislikeToVideoFollowers, sendCreateViewToVideoFollowers } from '../send/send-create' |
9 | import { getVideoChannelActivityPubUrl } from '../url' | 9 | import { getVideoChannelActivityPubUrl } from '../url' |
10 | import { videoChannelActivityObjectToDBAttributes } from './misc' | 10 | import { videoChannelActivityObjectToDBAttributes } from './misc' |
11 | import { DislikeObject } from '../../../../shared/models/activitypub/objects/dislike-object' | ||
11 | 12 | ||
12 | async function processCreateActivity (activity: ActivityCreate) { | 13 | async function processCreateActivity (activity: ActivityCreate) { |
13 | const activityObject = activity.object | 14 | const activityObject = activity.object |
@@ -16,6 +17,8 @@ async function processCreateActivity (activity: ActivityCreate) { | |||
16 | 17 | ||
17 | if (activityType === 'View') { | 18 | if (activityType === 'View') { |
18 | return processCreateView(activityObject as ViewObject) | 19 | return processCreateView(activityObject as ViewObject) |
20 | } else if (activityType === 'Dislike') { | ||
21 | return processCreateDislike(account, activityObject as DislikeObject) | ||
19 | } else if (activityType === 'VideoChannel') { | 22 | } else if (activityType === 'VideoChannel') { |
20 | return processCreateVideoChannel(account, activityObject as VideoChannelObject) | 23 | return processCreateVideoChannel(account, activityObject as VideoChannelObject) |
21 | } else if (activityType === 'Flag') { | 24 | } else if (activityType === 'Flag') { |
@@ -34,6 +37,36 @@ export { | |||
34 | 37 | ||
35 | // --------------------------------------------------------------------------- | 38 | // --------------------------------------------------------------------------- |
36 | 39 | ||
40 | async function processCreateDislike (byAccount: AccountInstance, dislike: DislikeObject) { | ||
41 | const options = { | ||
42 | arguments: [ byAccount, dislike ], | ||
43 | errorMessage: 'Cannot dislike the video with many retries.' | ||
44 | } | ||
45 | |||
46 | return retryTransactionWrapper(createVideoDislike, options) | ||
47 | } | ||
48 | |||
49 | function createVideoDislike (byAccount: AccountInstance, dislike: DislikeObject) { | ||
50 | return db.sequelize.transaction(async t => { | ||
51 | const video = await db.Video.loadByUrlAndPopulateAccount(dislike.object) | ||
52 | |||
53 | if (!video) throw new Error('Unknown video ' + dislike.object) | ||
54 | |||
55 | const rate = { | ||
56 | type: 'dislike' as 'dislike', | ||
57 | videoId: video.id, | ||
58 | accountId: byAccount.id | ||
59 | } | ||
60 | const [ , created ] = await db.AccountVideoRate.findOrCreate({ | ||
61 | where: rate, | ||
62 | defaults: rate | ||
63 | }) | ||
64 | await video.increment('dislikes') | ||
65 | |||
66 | if (video.isOwned() && created === true) await sendCreateDislikeToVideoFollowers(byAccount, video, undefined) | ||
67 | }) | ||
68 | } | ||
69 | |||
37 | async function processCreateView (view: ViewObject) { | 70 | async function processCreateView (view: ViewObject) { |
38 | const video = await db.Video.loadByUrlAndPopulateAccount(view.object) | 71 | const video = await db.Video.loadByUrlAndPopulateAccount(view.object) |
39 | 72 | ||