- const rate = {
- type: 'like' as 'like',
- videoId: video.id,
- accountId: byAccount.id
- }
- const [ , created ] = await AccountVideoRateModel.findOrCreate({
- where: rate,
- defaults: immutableAssign(rate, { url: getVideoLikeActivityPubUrl(byActor, video) }),
- transaction: t
- })
- if (created === true) await video.increment('likes', { transaction: t })
-
- if (video.isOwned() && created === true) {
- // Don't resend the activity to the sender
- const exceptions = [ byActor ]
-
- await forwardVideoRelatedActivity(activity, t, exceptions, video)
+ const video = await VideoModel.loadFull(onlyVideo.id, t)
+
+ const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t)
+ if (existingRate && existingRate.type === 'like') return
+
+ if (existingRate && existingRate.type === 'dislike') {
+ await video.decrement('dislikes', { transaction: t })
+ video.dislikes--