diff options
Diffstat (limited to 'server/lib/activitypub/process/process-dislike.ts')
-rw-r--r-- | server/lib/activitypub/process/process-dislike.ts | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts index bfd69e07a..ed8afd3d2 100644 --- a/server/lib/activitypub/process/process-dislike.ts +++ b/server/lib/activitypub/process/process-dislike.ts | |||
@@ -29,20 +29,21 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct | |||
29 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) | 29 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) |
30 | 30 | ||
31 | return sequelizeTypescript.transaction(async t => { | 31 | return sequelizeTypescript.transaction(async t => { |
32 | const rate = { | 32 | const url = getVideoDislikeActivityPubUrl(byActor, video) |
33 | |||
34 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) | ||
35 | if (existingRate && existingRate.type === 'dislike') return | ||
36 | |||
37 | await AccountVideoRateModel.create({ | ||
33 | type: 'dislike' as 'dislike', | 38 | type: 'dislike' as 'dislike', |
34 | videoId: video.id, | 39 | videoId: video.id, |
35 | accountId: byAccount.id | 40 | accountId: byAccount.id, |
36 | } | 41 | url |
42 | }, { transaction: t }) | ||
37 | 43 | ||
38 | const [ , created ] = await AccountVideoRateModel.findOrCreate({ | 44 | await video.increment('dislikes', { transaction: t }) |
39 | where: rate, | ||
40 | defaults: Object.assign({}, rate, { url: getVideoDislikeActivityPubUrl(byActor, video) }), | ||
41 | transaction: t | ||
42 | }) | ||
43 | if (created === true) await video.increment('dislikes', { transaction: t }) | ||
44 | 45 | ||
45 | if (video.isOwned() && created === true) { | 46 | if (video.isOwned()) { |
46 | // Don't resend the activity to the sender | 47 | // Don't resend the activity to the sender |
47 | const exceptions = [ byActor ] | 48 | const exceptions = [ byActor ] |
48 | 49 | ||