]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-dislike.ts
Fix HLS transcoding
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-dislike.ts
index bfd69e07a2dd4223e5782a511506f542571ecb39..c46180617414f426b8c798a7bb8c49fa4ce3c38d 100644 (file)
@@ -29,20 +29,25 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct
   const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject })
 
   return sequelizeTypescript.transaction(async t => {
-    const rate = {
+    const url = getVideoDislikeActivityPubUrl(byActor, video)
+
+    const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url)
+    if (existingRate && existingRate.type === 'dislike') return
+
+    await AccountVideoRateModel.create({
       type: 'dislike' as 'dislike',
       videoId: video.id,
-      accountId: byAccount.id
-    }
+      accountId: byAccount.id,
+      url
+    }, { transaction: t })
 
-    const [ , created ] = await AccountVideoRateModel.findOrCreate({
-      where: rate,
-      defaults: Object.assign({}, rate, { url: getVideoDislikeActivityPubUrl(byActor, video) }),
-      transaction: t
-    })
-    if (created === true) await video.increment('dislikes', { transaction: t })
+    await video.increment('dislikes', { transaction: t })
+
+    if (existingRate && existingRate.type === 'like') {
+      await video.decrement('likes', { transaction: t })
+    }
 
-    if (video.isOwned() && created === true) {
+    if (video.isOwned()) {
       // Don't resend the activity to the sender
       const exceptions = [ byActor ]